結果

問題 No.1522 Unfairness
ユーザー roarisroaris
提出日時 2021-05-31 02:48:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 390 ms / 2,000 ms
コード長 478 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 135,936 KB
最終ジャッジ日時 2024-04-29 21:58:54
合計ジャッジ時間 5,531 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,376 KB
testcase_01 AC 46 ms
53,504 KB
testcase_02 AC 46 ms
53,632 KB
testcase_03 AC 156 ms
91,520 KB
testcase_04 AC 85 ms
71,680 KB
testcase_05 AC 75 ms
68,608 KB
testcase_06 AC 66 ms
66,560 KB
testcase_07 AC 208 ms
90,624 KB
testcase_08 AC 184 ms
89,728 KB
testcase_09 AC 70 ms
67,584 KB
testcase_10 AC 110 ms
84,352 KB
testcase_11 AC 83 ms
70,272 KB
testcase_12 AC 136 ms
88,576 KB
testcase_13 AC 245 ms
112,896 KB
testcase_14 AC 83 ms
70,784 KB
testcase_15 AC 379 ms
135,680 KB
testcase_16 AC 390 ms
135,936 KB
testcase_17 AC 388 ms
135,552 KB
testcase_18 AC 383 ms
135,808 KB
testcase_19 AC 385 ms
135,808 KB
testcase_20 AC 352 ms
135,552 KB
testcase_21 AC 45 ms
53,504 KB
testcase_22 AC 45 ms
53,248 KB
testcase_23 AC 48 ms
54,016 KB
testcase_24 AC 67 ms
65,920 KB
testcase_25 AC 55 ms
61,312 KB
testcase_26 AC 67 ms
65,920 KB
testcase_27 AC 46 ms
53,888 KB
testcase_28 AC 54 ms
61,568 KB
testcase_29 AC 67 ms
66,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

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(1, N+1):
    for j in range(M+1):
        dp[i][j] = max(dp[i][j], dp[i-1][j])
    
    if i>=2:
        for j in range(M+1):
            k = j+A[i-2]-A[i-1]
            
            if k<=M:
                dp[i][k] = max(dp[i][k], dp[i-2][j]+A[i-2])

print(max(dp[N]))
0