Submission #68182991


Source Code Expand

N = int(input())
P = []
A = []
B = []
    
for _ in range(N):
    p, a, b = map(int, input().split())
    P.append(p)
    A.append(a)
    B.append(b)

dp = [[0] * 1001 for _ in range(N+1)]
for t in range(1001):
    dp[-1][t] = t
    
for n in range(N-1, -1, -1):
    cdp = dp[n]
    ndp = dp[n+1]
    p, a, b = P[n], A[n], B[n]
    for t in range(1001):
        if p >= t:
            cdp[t] = ndp[t + a]
        else:
            cdp[t] = ndp[max(0, t - b)]

Bsum = [0]
for b in B:
    Bsum.append(Bsum[-1] + b)

from bisect import bisect_left


Q = int(input())
for _ in range(Q):
    X = int(input())
    if X > 1000:
        pos = bisect_left(Bsum, X-1000)
        if pos == len(Bsum):
            X -= Bsum[-1]
            print(X)
        else:
            X -= Bsum[pos]
            print(dp[pos][X])
    else:
        print(dp[0][X])

    

Submission Info

Submission Time
Task D - Takahashi's Expectation
User catupper
Language Python (PyPy 3.10-v7.3.12)
Score 425
Code Size 895 Byte
Status AC
Exec Time 931 ms
Memory 164336 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 30
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 61 ms 80904 KiB
00_sample_01.txt AC 62 ms 81204 KiB
00_sample_02.txt AC 64 ms 81208 KiB
01_random_03.txt AC 923 ms 163396 KiB
01_random_04.txt AC 918 ms 163256 KiB
01_random_05.txt AC 920 ms 163448 KiB
01_random_06.txt AC 918 ms 163640 KiB
01_random_07.txt AC 929 ms 163720 KiB
01_random_08.txt AC 925 ms 163436 KiB
01_random_09.txt AC 915 ms 163568 KiB
01_random_10.txt AC 925 ms 163208 KiB
01_random_11.txt AC 931 ms 163428 KiB
01_random_12.txt AC 923 ms 163432 KiB
01_random_13.txt AC 928 ms 163368 KiB
01_random_14.txt AC 922 ms 163332 KiB
01_random_15.txt AC 925 ms 163496 KiB
01_random_16.txt AC 363 ms 113908 KiB
01_random_17.txt AC 398 ms 85992 KiB
01_random_18.txt AC 856 ms 145228 KiB
01_random_19.txt AC 268 ms 107524 KiB
01_random_20.txt AC 332 ms 131264 KiB
01_random_21.txt AC 842 ms 118300 KiB
01_random_22.txt AC 821 ms 87004 KiB
01_random_23.txt AC 502 ms 89656 KiB
01_random_24.txt AC 896 ms 163780 KiB
01_random_25.txt AC 911 ms 163352 KiB
01_random_26.txt AC 910 ms 164336 KiB
01_random_27.txt AC 905 ms 163284 KiB
01_random_28.txt AC 913 ms 163336 KiB
01_random_29.txt AC 919 ms 163340 KiB