結果

問題 No.1522 Unfairness
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-29 10:53:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 147,200 KB
最終ジャッジ日時 2024-04-29 21:58:07
合計ジャッジ時間 5,182 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,968 KB
testcase_01 AC 44 ms
51,840 KB
testcase_02 AC 43 ms
51,840 KB
testcase_03 AC 147 ms
94,464 KB
testcase_04 AC 79 ms
71,296 KB
testcase_05 AC 68 ms
66,304 KB
testcase_06 AC 57 ms
62,848 KB
testcase_07 AC 189 ms
103,296 KB
testcase_08 AC 181 ms
103,296 KB
testcase_09 AC 62 ms
65,152 KB
testcase_10 AC 99 ms
83,584 KB
testcase_11 AC 71 ms
68,224 KB
testcase_12 AC 117 ms
87,936 KB
testcase_13 AC 228 ms
114,688 KB
testcase_14 AC 68 ms
67,712 KB
testcase_15 AC 356 ms
146,688 KB
testcase_16 AC 358 ms
146,816 KB
testcase_17 AC 372 ms
146,816 KB
testcase_18 AC 362 ms
147,200 KB
testcase_19 AC 357 ms
146,944 KB
testcase_20 AC 315 ms
146,816 KB
testcase_21 AC 40 ms
51,968 KB
testcase_22 AC 41 ms
51,968 KB
testcase_23 AC 42 ms
52,224 KB
testcase_24 AC 60 ms
63,488 KB
testcase_25 AC 45 ms
57,856 KB
testcase_26 AC 59 ms
63,616 KB
testcase_27 AC 40 ms
51,968 KB
testcase_28 AC 45 ms
58,496 KB
testcase_29 AC 57 ms
62,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

# dp[i,j]: i番目の要素を取る、不平等さj -> Oの最大値
#隣り合う2つをO, Eとするのがベスト
dp = [[0] * (P + 1) for _ in range(N + 2)]
for i in range(1, N):
    get = A[i]
    pena = A[i] - A[i-1]
    for j in range(P+1):
        dp[i][j] = max(dp[i][j], dp[i-1][j])
    for j in reversed(range(pena, P+1)):
        dp[i+1][j] = max(dp[i+1][j], dp[i-1][j-pena] + get)
for i in range(P+1):
    dp[N][i] = max(dp[N][i], dp[N-1][i])

print(max(dp[N]))
0