def test_all(f):
for i, data in enumerate(eval(f"test_data{f.__name__[0]}")):
exp = data["out"]
ans = f(*data["in"])
result = "AC" if exp == ans else "WA"
print(f"{i+1} {result}: expected: {exp}, output: {ans}")
from operator import itemgetter as ig
def B(N, X, Y, Z, A, B):
ans = []
(*data,) = zip(range(1, N + 1), A, B)
# 数学
data.sort(key=ig(1), reverse=True)
n, *_ = zip(*data)
ans.extend(n[:X])
data = data[X:]
# 英語
data.sort(key=ig(0))
data.sort(key=ig(2), reverse=True)
n, *_ = zip(*data)
ans.extend(n[:Y])
data = data[Y:]
# 合計
data = [(n, a + b) for n, a, b in data]
data.sort(key=ig(0))
data.sort(key=ig(1), reverse=True)
n, *_ = zip(*data)
ans.extend(n[:Z])
return "\n".join(map(str, sorted(ans)))test_all(B)
from operator import add, itemgetter
def B(N, X, Y, Z, A, B):
def f(points, n):
v = sorted((-p, i) for i, p in enumerate(points, 1) if i not in ans)
ans.extend(map(itemgetter(1), v[:n]))
ans = []
f(A, X)
f(B, Y)
f(map(add, A, B), Z)
return "\n".join(map(str, sorted(ans)))test_all(B)
from bisect import bisect
from operator import itemgetter as ig
def D(N, K, P):
if K == 1:
return "\n".join(map(str, P))
if K == N and P == sorted(P):
return "\n".join(str(N) * N)
ans = [-1] * (N + 1)
ba = []
for i, v in enumerate(P, start=1):
idx = bisect(list(map(ig(0), ba)), v)
if idx == len(ba):
ba.append([v])
else:
if len(ba[idx]) == K - 1:
for c in ba[idx]:
ans[c] = i
ans[v] = i
ba.remove(ba[idx])
else:
ba[idx].insert(0, v)
return "\n".join(map(str, ans[1:]))test_all(D)
from bisect import bisect
from operator import itemgetter as ig
def D(N, K, P):
if K == 1:
return "\n".join(map(str, P))
if K == N and P == sorted(P):
return "\n".join(str(N) * N)
ans = [-1] * (N + 1)
ba = []
top = []
for i, v in enumerate(P, start=1):
idx = bisect(top, v)
if idx == len(ba):
ba.append([v])
top.append(v)
else:
yama = ba[idx]
yama.append(v)
top[idx] = v
if len(yama) == K:
for c in yama:
ans[c] = i
ba.pop(idx)
top.pop(idx)
return "\n".join(map(str, ans[1:]))test_all(D)
from bisect import bisect
from operator import itemgetter as ig
def D(N, K, P):
if K == 1:
ans, _ = zip(*sorted(zip(range(1, N + 1), P), key=ig(1)))
return "\n".join(map(str, ans))
ans = [-1] * (N + 1)
ba = []
top = []
for i, v in enumerate(P, start=1):
idx = bisect(top, v)
if idx == len(ba):
ba.append([v])
top.append(v)
else:
yama = ba[idx]
yama.append(v)
top[idx] = v
if len(yama) == K:
for c in yama:
ans[c] = i
ba.pop(idx)
top.pop(idx)
return "\n".join(map(str, ans[1:]))test_all(D)
from bisect import bisect
from operator import itemgetter as ig
def D(N, K, P):
ans = [-1] * (N + 1)
ba = []
top = []
for i, v in enumerate(P, start=1):
idx = bisect(top, v)
if idx == len(ba):
yama = [v]
ba.append(yama)
top.append(v)
else:
yama = ba[idx]
yama.append(v)
top[idx] = v
if len(yama) == K:
for c in yama:
ans[c] = i
ba.pop(idx)
top.pop(idx)
return "\n".join(map(str, ans[1:]))test_all(D)