結果

問題 No.1522 Unfairness
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-05-04 01:32:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 531 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 45,756 KB
最終ジャッジ日時 2023-09-29 21:51:26
合計ジャッジ時間 6,808 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,828 KB
testcase_01 AC 17 ms
7,860 KB
testcase_02 AC 16 ms
7,964 KB
testcase_03 TLE -
testcase_04 AC 519 ms
13,432 KB
testcase_05 AC 184 ms
10,192 KB
testcase_06 AC 25 ms
8,588 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 18

#入力
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)] #dp配列
w = [a[i] - a[i + 1] for i in range(n - 1)] #重さ
v = [a[i] for i in range(n - 1)] #価値

#ナップサックdpの計算
for i in range(n):
    for j in range(m + 1):
        if i < n - 1 and j + w[i] <= m:
            dp[i + 2][j + w[i]] = dp[i][j] + v[i]
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

ans = max(dp[n])

print(ans)
0