QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#679491#7678. The GamemengxinzclTL 0ms0kbPython31.2kb2024-10-26 17:44:052024-10-26 17:44:06

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 17:44:06]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-26 17:44:05]
  • 提交

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)

詳細信息

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

output:


result: