QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#679491 | #7678. The Game | mengxinzcl | TL | 0ms | 0kb | Python3 | 1.2kb | 2024-10-26 17:44:05 | 2024-10-26 17:44:06 |
answer
from collections import deque
for i in range(int(input())):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
suma=sum(a[-m::])
sumb=sum(b)
k=sumb-suma
if k<0:
print(-1)
continue
ms=a[-m::]
minmi=0
res=[]
if n-m>k: #tk 为总和差值,cz为总操作数
cz=n-m
tk=k+0
xl=deque(a[0:-m])
while cz>tk and xl:
if xl[0]>ms[0]:
cz-=1
res.append(xl.popleft())
for i in range(m-1,-1,-1):
if ms[i]<=b[i]:
for j in range(b[i]-ms[i]):
res.append(ms[i])
ms[i]+=1
else:
res=-1
break
elif n-m==k:
for i in range(m-1,-1,-1):
if ms[i]<=b[i]:
for j in range(b[i]-ms[i]):
res.append(ms[i])
ms[i]+=1
else:
res=-1
break
elif n-m<k:
print(-1)
continue
print(*res)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
6 5 3 1 2 2 3 3 2 3 4 4 2 1 2 2 4 2 4 5 2 2 3 3 4 4 5 5 6 1 1 1 1 1 1 1 4 4 2 1 1 1 2 2 2 4 1 1 1 1 1 2