結果
| 問題 |
No.2329 Nafmo、イカサマをする
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 12:53:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 997 bytes |
| コンパイル時間 | 136 ms |
| コンパイル使用メモリ | 82,824 KB |
| 実行使用メモリ | 54,164 KB |
| 最終ジャッジ日時 | 2025-06-12 12:55:12 |
| 合計ジャッジ時間 | 3,422 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 26 |
ソースコード
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
# Handle the case when there are no cards
if n == 0:
print(0)
exit()
# Sort the cards in descending order
a_sorted = sorted(a, reverse=True)
max_a = a_sorted[0]
# Initialize dp array where dp[i] is the maximum sum with i draws
dp = [0] * (k + 1)
for i in range(1, k + 1):
current_max = dp[i-1]
# Try to take the largest possible a
candidate = current_max + max_a
if candidate <= m:
dp[i] = candidate
else:
# Find the largest a that can be added without exceeding m
found = False
for a_val in a_sorted:
if current_max + a_val <= m:
dp[i] = current_max + a_val
found = True
break
if not found:
dp[i] = current_max # cannot draw, keep the previous max
# Check if not drawing is better
dp[i] = max(dp[i], dp[i-1])
# The answer is the maximum value in dp[0...k]
print(max(dp))
gew1fw