結果

問題 No.1522 Unfairness
ユーザー convexineqconvexineq
提出日時 2021-05-28 22:11:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 137,216 KB
最終ジャッジ日時 2024-04-29 21:56:52
合計ジャッジ時間 5,299 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
51,840 KB
testcase_01 AC 37 ms
52,224 KB
testcase_02 AC 35 ms
51,968 KB
testcase_03 AC 137 ms
93,440 KB
testcase_04 AC 68 ms
72,064 KB
testcase_05 AC 63 ms
67,968 KB
testcase_06 AC 48 ms
62,720 KB
testcase_07 AC 151 ms
92,016 KB
testcase_08 AC 154 ms
91,008 KB
testcase_09 AC 51 ms
64,512 KB
testcase_10 AC 90 ms
83,584 KB
testcase_11 AC 61 ms
68,992 KB
testcase_12 AC 104 ms
88,192 KB
testcase_13 AC 245 ms
114,200 KB
testcase_14 AC 61 ms
68,864 KB
testcase_15 AC 411 ms
137,216 KB
testcase_16 AC 415 ms
136,960 KB
testcase_17 AC 417 ms
136,832 KB
testcase_18 AC 400 ms
136,960 KB
testcase_19 AC 418 ms
136,832 KB
testcase_20 AC 330 ms
136,576 KB
testcase_21 AC 38 ms
51,968 KB
testcase_22 AC 38 ms
52,480 KB
testcase_23 AC 39 ms
52,992 KB
testcase_24 AC 57 ms
65,408 KB
testcase_25 AC 42 ms
58,240 KB
testcase_26 AC 54 ms
63,744 KB
testcase_27 AC 38 ms
52,352 KB
testcase_28 AC 41 ms
57,600 KB
testcase_29 AC 48 ms
61,952 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