結果

問題 No.1522 Unfairness
ユーザー ああいいああいい
提出日時 2022-02-26 14:33:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 766 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 136,524 KB
最終ジャッジ日時 2023-09-17 15:41:13
合計ジャッジ時間 6,708 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,324 KB
testcase_01 AC 75 ms
71,124 KB
testcase_02 AC 74 ms
70,940 KB
testcase_03 AC 155 ms
92,344 KB
testcase_04 AC 102 ms
76,388 KB
testcase_05 AC 94 ms
76,732 KB
testcase_06 AC 84 ms
76,564 KB
testcase_07 AC 174 ms
91,128 KB
testcase_08 AC 172 ms
90,468 KB
testcase_09 AC 89 ms
76,720 KB
testcase_10 WA -
testcase_11 AC 94 ms
76,484 KB
testcase_12 AC 131 ms
89,464 KB
testcase_13 AC 231 ms
113,528 KB
testcase_14 AC 95 ms
76,152 KB
testcase_15 AC 344 ms
136,428 KB
testcase_16 WA -
testcase_17 AC 341 ms
136,524 KB
testcase_18 AC 346 ms
136,320 KB
testcase_19 AC 346 ms
136,060 KB
testcase_20 AC 320 ms
136,056 KB
testcase_21 AC 78 ms
71,240 KB
testcase_22 AC 77 ms
71,520 KB
testcase_23 AC 77 ms
71,264 KB
testcase_24 AC 88 ms
75,716 KB
testcase_25 AC 80 ms
75,560 KB
testcase_26 AC 87 ms
76,072 KB
testcase_27 AC 78 ms
71,484 KB
testcase_28 AC 80 ms
75,616 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)

import sys
if N == 2:
    d = A[0] - A[1]
    if d <= M:
        print(A[0])
    else:
        print(0)
    exit()
    
inf = 10 ** 10
dp = [[0] * (M+1) for _ in range(N-1)]
if A[0] - A[1] <= M:
    dp[0][A[0]-A[1]] = A[0]
if A[1] - A[2] <= M:
    dp[1][A[1]-A[2]] = A[1]
for i in range(1,N-1):
    d = A[i] - A[i+1]
    for j in range(M+1):
        dp[i][j] = dp[i-1][j]
    if i == 1:continue
    for j in range(M+1):
        if j + d <= M:
            dp[i][j+d] = max(dp[i][j+d],dp[i-2][j] + A[i])
        else:
            break
_max = 0
for j in range(M+1):
    if dp[-1][j] > _max:
        _max = dp[-1][j]
    if dp[-2][j] > _max:
        _max = dp[-2][j]
print(_max)
0