結果

問題 No.1522 Unfairness
ユーザー convexineqconvexineq
提出日時 2021-05-28 22:11:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 468 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 148,236 KB
最終ジャッジ日時 2023-08-12 07:28:25
合計ジャッジ時間 6,930 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,472 KB
testcase_01 AC 72 ms
71,328 KB
testcase_02 AC 73 ms
71,304 KB
testcase_03 AC 175 ms
93,204 KB
testcase_04 AC 110 ms
81,764 KB
testcase_05 AC 97 ms
76,868 KB
testcase_06 AC 84 ms
76,708 KB
testcase_07 AC 202 ms
104,412 KB
testcase_08 AC 203 ms
104,332 KB
testcase_09 AC 87 ms
76,460 KB
testcase_10 AC 123 ms
85,112 KB
testcase_11 AC 97 ms
76,192 KB
testcase_12 AC 138 ms
89,508 KB
testcase_13 AC 282 ms
113,596 KB
testcase_14 AC 97 ms
76,280 KB
testcase_15 AC 462 ms
148,072 KB
testcase_16 AC 461 ms
148,048 KB
testcase_17 AC 461 ms
148,236 KB
testcase_18 AC 468 ms
147,828 KB
testcase_19 AC 467 ms
148,044 KB
testcase_20 AC 362 ms
136,240 KB
testcase_21 AC 75 ms
71,436 KB
testcase_22 AC 73 ms
71,488 KB
testcase_23 AC 73 ms
71,256 KB
testcase_24 AC 93 ms
76,656 KB
testcase_25 AC 76 ms
75,720 KB
testcase_26 AC 88 ms
75,924 KB
testcase_27 AC 72 ms
71,328 KB
testcase_28 AC 76 ms
75,820 KB
testcase_29 AC 83 ms
76,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
*a, = map(int,input().split())
a.sort(reverse=1)
ans = 0
dp = [[0]*(m+1) for _ in range(n+1)]
for i in range(n+1):
    D = dp[i]
    if i+1 <= n:
        for j in range(m+1):
            dp[i+1][j] = max(dp[i+1][j],D[j])
    if i+2 <= n:
        v = a[i]-a[i+1]
        for j in range(m+1-v):
            dp[i+2][j+v] = max(dp[i+2][j+v],D[j]+a[i])
    if i+3 <= n:
        v = a[i]-a[i+2]
        for j in range(m+1-v):
            dp[i+3][j+v] = max(dp[i+3][j+v],D[j]+a[i])
print(max(dp[-1]))
0