就是一个大模拟。。。
不过出了一个小插曲,刚开是TLE了,但没想到仅仅改了下面的两行代码就AC了
↓
n,m=map(int,input().split())#计算机个数,任务数
v=[int(i) for i in input().split()]#每个计算机的算力
a=[]
for i in range(m):
aa=list(map(int,input().split()))+[i]
a.append(aa)
#print(a)
#h=[]
a.sort(key = lambda x: (x[1],x[0]))
h=[ 0 for i in range(m+1)]
i=0
while( i < m ):
capity=v[a[i][1]-1]
start=0
flag=a[i][1]
temp=[]
#print(a[i][1])
while(i<m and a[i][1] == flag):
ai,bi,ci,di,ei=a[i]
tt=[]
start =ai
for j in temp:
if j[0]<=start :
capity += j[1]
else:
tt.append(j)
temp=tt
if di <= capity :
temp.append([ai+ci,di])
capity -= di
h[ei]=capity
else:
h[ei]=-1
i+=1
for j in h[:-1]:
print(j)