結果

問題 No.974 最後の日までに
ユーザー convexineqconvexineq
提出日時 2021-05-05 02:24:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,667 ms / 2,000 ms
コード長 761 bytes
コンパイル時間 575 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 182,976 KB
最終ジャッジ日時 2023-10-01 04:26:38
合計ジャッジ時間 54,229 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,443 ms
178,120 KB
testcase_01 AC 1,486 ms
178,824 KB
testcase_02 AC 1,461 ms
178,804 KB
testcase_03 AC 1,419 ms
178,672 KB
testcase_04 AC 1,437 ms
181,940 KB
testcase_05 AC 1,435 ms
179,196 KB
testcase_06 AC 1,465 ms
179,168 KB
testcase_07 AC 1,415 ms
178,516 KB
testcase_08 AC 1,429 ms
178,924 KB
testcase_09 AC 1,437 ms
178,848 KB
testcase_10 AC 1,465 ms
179,376 KB
testcase_11 AC 1,475 ms
178,996 KB
testcase_12 AC 1,467 ms
179,252 KB
testcase_13 AC 1,450 ms
181,820 KB
testcase_14 AC 1,467 ms
181,560 KB
testcase_15 AC 1,504 ms
179,100 KB
testcase_16 AC 1,481 ms
182,976 KB
testcase_17 AC 1,041 ms
180,060 KB
testcase_18 AC 1,101 ms
179,272 KB
testcase_19 AC 1,063 ms
179,944 KB
testcase_20 AC 1,061 ms
179,432 KB
testcase_21 AC 1,069 ms
179,668 KB
testcase_22 AC 1,066 ms
179,376 KB
testcase_23 AC 1,077 ms
179,560 KB
testcase_24 AC 1,088 ms
179,488 KB
testcase_25 AC 88 ms
75,848 KB
testcase_26 AC 95 ms
76,064 KB
testcase_27 AC 1,285 ms
156,676 KB
testcase_28 AC 1,505 ms
181,860 KB
testcase_29 AC 73 ms
71,372 KB
testcase_30 AC 1,214 ms
178,664 KB
testcase_31 AC 74 ms
71,396 KB
testcase_32 AC 74 ms
71,292 KB
testcase_33 AC 1,032 ms
146,076 KB
testcase_34 AC 1,667 ms
180,944 KB
testcase_35 AC 74 ms
71,352 KB
testcase_36 AC 74 ms
71,336 KB
testcase_37 AC 1,339 ms
178,356 KB
testcase_38 AC 73 ms
71,100 KB
testcase_39 AC 73 ms
71,360 KB
testcase_40 AC 984 ms
160,348 KB
testcase_41 AC 1,072 ms
178,496 KB
testcase_42 AC 1,363 ms
179,612 KB
testcase_43 AC 1,354 ms
179,220 KB
testcase_44 AC 1,133 ms
158,612 KB
testcase_45 AC 918 ms
138,560 KB
testcase_46 AC 73 ms
71,256 KB
testcase_47 AC 73 ms
71,268 KB
testcase_48 AC 73 ms
71,336 KB
testcase_49 AC 71 ms
71,440 KB
testcase_50 AC 72 ms
71,112 KB
testcase_51 AC 74 ms
71,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(t,m,v,w):
    global ans
    if t==w:
        L.append([m,v])
        return
    dfs(t+1,m+a[t],v,w)
    if t+1 < w: dfs(t+2,m-c[t+1],v+b[t+1],w)

def solve(x,y):
    x.sort(key=f)
    y.sort(key=f)
    for i in range(len(x)-1)[::-1]:
        if x[i][1] < x[i+1][1]: x[i][1] = x[i+1][1]
    ans = idx = 0
    L = len(x)
    for m,v in y[::-1]:
        while idx < L and x[idx][0] + m < 0:
            idx += 1
        if idx < L:
            ans = max(ans,x[idx][1]+v)
    return ans

w = int(input())
a,b,c = [0]*w, [0]*w, [0]*w
for i in range(w):
    a[i],b[i],c[i] = map(int,input().split())
ans = 0
for W in [w//2,w//2+1]:
    f = lambda x:x[0]
    L = x = []
    dfs(0,0,0,W)
    L = y = []
    dfs(W,0,0,w)
    ans = max(ans,solve(x,y))
print(ans)
0