結果

問題 No.1522 Unfairness
ユーザー ああいいああいい
提出日時 2022-02-26 14:35:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 136,332 KB
最終ジャッジ日時 2023-09-17 15:44:18
合計ジャッジ時間 5,890 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,152 KB
testcase_01 AC 77 ms
71,364 KB
testcase_02 AC 76 ms
71,144 KB
testcase_03 AC 151 ms
91,880 KB
testcase_04 AC 93 ms
76,284 KB
testcase_05 AC 86 ms
76,804 KB
testcase_06 AC 81 ms
76,492 KB
testcase_07 AC 169 ms
91,124 KB
testcase_08 AC 167 ms
90,228 KB
testcase_09 AC 84 ms
76,480 KB
testcase_10 AC 108 ms
85,100 KB
testcase_11 AC 89 ms
76,036 KB
testcase_12 AC 124 ms
89,132 KB
testcase_13 AC 225 ms
113,356 KB
testcase_14 AC 89 ms
76,292 KB
testcase_15 AC 339 ms
136,332 KB
testcase_16 AC 340 ms
136,272 KB
testcase_17 AC 340 ms
136,188 KB
testcase_18 AC 341 ms
136,268 KB
testcase_19 AC 339 ms
136,228 KB
testcase_20 AC 321 ms
136,012 KB
testcase_21 AC 75 ms
71,120 KB
testcase_22 AC 74 ms
71,128 KB
testcase_23 AC 77 ms
71,120 KB
testcase_24 AC 85 ms
75,932 KB
testcase_25 AC 77 ms
75,408 KB
testcase_26 AC 85 ms
75,972 KB
testcase_27 AC 74 ms
71,180 KB
testcase_28 AC 77 ms
75,548 KB
testcase_29 AC 88 ms
76,116 KB
権限があれば一括ダウンロードができます

ソースコード

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:
        if d <= M:
            dp[i][d] = max(dp[i][d],A[i])
        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