結果

問題 No.1522 Unfairness
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-05-28 21:16:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 415 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 81,972 KB
実行使用メモリ 147,200 KB
最終ジャッジ日時 2024-04-29 21:54:26
合計ジャッジ時間 5,536 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,352 KB
testcase_01 AC 39 ms
51,968 KB
testcase_02 AC 40 ms
52,096 KB
testcase_03 AC 141 ms
92,800 KB
testcase_04 AC 74 ms
71,936 KB
testcase_05 AC 71 ms
69,504 KB
testcase_06 AC 59 ms
66,432 KB
testcase_07 AC 187 ms
103,444 KB
testcase_08 AC 192 ms
103,168 KB
testcase_09 AC 59 ms
66,560 KB
testcase_10 AC 102 ms
83,712 KB
testcase_11 AC 66 ms
68,844 KB
testcase_12 AC 117 ms
88,576 KB
testcase_13 AC 256 ms
114,944 KB
testcase_14 AC 74 ms
68,992 KB
testcase_15 AC 415 ms
146,944 KB
testcase_16 AC 415 ms
146,952 KB
testcase_17 AC 404 ms
147,072 KB
testcase_18 AC 405 ms
146,960 KB
testcase_19 AC 404 ms
147,200 KB
testcase_20 AC 263 ms
136,960 KB
testcase_21 AC 39 ms
51,968 KB
testcase_22 AC 40 ms
51,840 KB
testcase_23 AC 41 ms
52,608 KB
testcase_24 AC 60 ms
65,192 KB
testcase_25 AC 46 ms
58,624 KB
testcase_26 AC 56 ms
64,000 KB
testcase_27 AC 40 ms
51,840 KB
testcase_28 AC 47 ms
58,496 KB
testcase_29 AC 57 ms
63,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

大きい順にソートする
不平等さはなるべく小さくしたい
Eが無いのは損にしかならない
Oを取ると直後にEを取る
でOK

"""

from sys import stdin
import sys

N,M = map(int,stdin.readline().split())

A = list(map(int,stdin.readline().split()))

A.sort()
A.reverse()
A.append(0)

dp = [[0] * (M+1) for i in range(N+2)]
ans = 0

#print (A)
for i in range(N-1):

    pl = A[i]-A[i+1]
    for j in range(M+1):
        dp[i+1][j] = max(dp[i+1][j] , dp[i][j])
        if j + pl <= M:
            dp[i+2][j+pl] = max(dp[i+2][j+pl] , dp[i][j] + A[i])

#print (dp)
for i in range(N+2):
    ans = max(ans,max(dp[i]))

print (ans)
0