結果

問題 No.1522 Unfairness
ユーザー H3PO4H3PO4
提出日時 2023-10-04 11:42:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 437 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 136,708 KB
最終ジャッジ日時 2023-10-04 11:42:42
合計ジャッジ時間 6,130 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,300 KB
testcase_01 AC 69 ms
71,312 KB
testcase_02 AC 70 ms
71,432 KB
testcase_03 AC 168 ms
92,444 KB
testcase_04 AC 95 ms
76,384 KB
testcase_05 AC 89 ms
76,724 KB
testcase_06 AC 82 ms
76,748 KB
testcase_07 AC 180 ms
91,512 KB
testcase_08 AC 182 ms
90,580 KB
testcase_09 AC 85 ms
76,732 KB
testcase_10 AC 101 ms
77,096 KB
testcase_11 AC 87 ms
76,140 KB
testcase_12 AC 127 ms
89,600 KB
testcase_13 AC 209 ms
113,640 KB
testcase_14 AC 93 ms
76,716 KB
testcase_15 AC 290 ms
136,488 KB
testcase_16 AC 290 ms
136,672 KB
testcase_17 AC 290 ms
136,444 KB
testcase_18 AC 290 ms
136,588 KB
testcase_19 AC 290 ms
136,708 KB
testcase_20 AC 354 ms
136,708 KB
testcase_21 AC 71 ms
71,396 KB
testcase_22 AC 72 ms
71,300 KB
testcase_23 AC 72 ms
71,268 KB
testcase_24 AC 89 ms
76,160 KB
testcase_25 AC 77 ms
75,892 KB
testcase_26 AC 82 ms
76,280 KB
testcase_27 AC 70 ms
71,304 KB
testcase_28 AC 79 ms
75,924 KB
testcase_29 AC 83 ms
75,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
dp = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(N - 1):
    for m in range(M + 1):
        dp[i + 2][m] = dp[i + 1][m]
    for m in range(M + 1):
        new_m = m + A[i] - A[i + 1]
        if new_m > M:
            continue
        if dp[i + 2][new_m] < dp[i][m] + A[i]:
            dp[i + 2][new_m] = dp[i][m] + A[i]
print(max(dp[N]))
0