結果
問題 |
No.2329 Nafmo、イカサマをする
|
ユーザー |
![]() |
提出日時 | 2025-04-15 21:20:51 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 998 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 81,748 KB |
実行使用メモリ | 54,120 KB |
最終ジャッジ日時 | 2025-04-15 21:26:30 |
合計ジャッジ時間 | 3,182 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 WA * 26 |
ソースコード
def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]); idx +=1 M = int(input[idx]); idx +=1 K = int(input[idx]); idx +=1 A = list(map(int, input[idx:idx+N])) if N > 0 else [] A.sort(reverse=True) # Sort in descending order # Handle cases where all A are 0 or N=0 if not A or A[0] == 0: print(0) return # Recursive function with memoization (not needed due to small K) def dfs(s, r): if r == 0: return s # Option 1: do not pick, current sum is s not_pick = s # Option 2: pick the best possible a best_a = 0 for a in A: if s + a <= M: best_a = a break if best_a == 0: pick = s # cannot pick any else: pick = dfs(s + best_a, r - 1) return max(pick, not_pick) result = dfs(0, K) print(result) if __name__ == "__main__": main()