QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#816235#9528. New Energy Vehiclehxu10#WA 15ms10600kbPython31.8kb2024-12-16 05:24:412024-12-16 05:24:42

Judging History

This is the latest submission verdict.

  • [2024-12-16 05:24:42]
  • Judged
  • Verdict: WA
  • Time: 15ms
  • Memory: 10600kb
  • [2024-12-16 05:24:41]
  • Submitted

answer

import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import heapq



def main():
    n,m = map(int,input().split())
    cap = list(map(int,input().split()))

    remain = cap[:]
    remaintot = sum(remain)


    charger = [[] for _ in range(n)]
    for _ in range(m):
        x,i = map(int,input().split())
        charger[i-1].append(x)


    inf = 10**18

    for i in range(n):
        charger[i].append(inf)
        charger[i] = charger[i][::-1]


#    print(charger)
    heap = []
    pending = []
    for i in range(n):
        heapq.heappush(heap,(charger[i].pop(), i))



    curr = 0

    while True:
        if remaintot==0:
            break
        nextgoal = inf 
        nextpending = inf
        if heap:
            nextgoal = min(curr + remain[heap[0][1]], heap[0][0])
        if pending:
            nextpending = pending[0][0]

#        print(curr, heap, nextgoal,nextpending,remain)

        if nextgoal < nextpending:
            diff = nextgoal - curr
            remaintot -= diff
            curr = nextgoal
            remain[heap[0][1]] -= diff
            heapq.heappush(pending, heapq.heappop(heap))
            continue 

        diff = nextpending - curr

#        print(curr,diff,nextpending,"diff",remaintot)
        if diff > remaintot:
            curr += remaintot
            break

        if diff > 0 and heap:
            remain[heap[0][1]] -= diff
            remaintot -= diff
            curr += diff

        nextc = pending[0][1]
        charged = cap[nextc] - remain[nextc]
        remain[nextc] = cap[nextc]
        remaintot += charged
        heapq.heappop(pending)
        heapq.heappush(heap, (charger[nextc].pop(), nextc))


    print(curr)
        
        
            
            
        


            

 
            


    






T = int(input())
t = 1
while t <= T:
    main()
    t += 1

詳細信息

Test #1:

score: 100
Accepted
time: 15ms
memory: 10600kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 10588kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
4
11
999999999
1000000000

result:

wrong answer 6th lines differ - expected: '2000000000', found: '1000000000'