QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#816242#9528. New Energy Vehiclehxu10#TL 974ms38196kbPython31.7kb2024-12-16 06:12:502024-12-16 06:12:51

Judging History

This is the latest submission verdict.

  • [2024-12-16 06:12:51]
  • Judged
  • Verdict: TL
  • Time: 974ms
  • Memory: 38196kb
  • [2024-12-16 06:12:50]
  • 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:
        nextgoal = inf 
        nextpending = inf
        if heap:
            nextgoal = min(curr + remain[heap[0][1]], heap[0][0])
        if pending:
            nextpending = pending[0][0]


        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

        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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 7ms
memory: 10628kb

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
2000000000

result:

ok 6 lines

Test #3:

score: 0
Accepted
time: 591ms
memory: 35800kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

1543020
1578939
1526016
1527381
1547404
1564631
1051729
1548178
1114634
1072253

result:

ok 10 lines

Test #4:

score: 0
Accepted
time: 974ms
memory: 38196kb

input:

3
100000 100000
1 2 1 1 10 1 17 34 1 1 20 14 4 24 3 1 3 2 7 4 6 3 1 18 1 4 2 1 3 8 3 2 4 1 10 4 23 14 4 16 4 9 8 3 5 2 6 2 2 3 1 7 3 25 10 3 5 3 1 2 14 3 1 3 8 19 3 4 5 7 4 22 2 2 3 3 8 11 8 8 1 9 1 4 2 10 9 8 13 7 21 14 1 27 4 3 2 13 8 1 3 1 5 1 1 1 12 3 4 2 4 10 2 2 10 2 2 14 1 11 1 1 6 1 1 1 2 4 ...

output:

1117713
1116035
1092827

result:

ok 3 lines

Test #5:

score: -100
Time Limit Exceeded

input:

3
100000 100000
2086 178 3183 10562 8083 1408 4312 2370 4331 1721 2154 6155 7176 1991 30048 7425 9493 1709 7640 3726 182 2462 1597 2865 649 8069 3419 6510 8556 680 49 68 9820 13378 799 2489 1466 8877 8695 2235 915 2579 524 6615 20680 7704 4325 4696 8853 5492 1417 4342 1740 2355 2255 5297 15035 5003 ...

output:

1099515229
1100014648
1105660500

result: