結果

問題 No.2329 Nafmo、イカサマをする
ユーザー lam6er
提出日時 2025-03-31 17:24:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 984 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 54,280 KB
最終ジャッジ日時 2025-03-31 17:24:39
合計ジャッジ時間 3,022 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, k = map(int, input().split())
a = list(map(int, input().split()))

if n == 0:
    print(0)
else:
    a.sort(reverse=True)
    max_a = a[0]
    dp = [0] * (k + 1)  # dp[0] is 0, others are initialized to 0

    for t in range(1, k + 1):
        current_max = 0
        # Iterate through all elements in a, sorted descendingly
        for ai in a:
            prev = dp[t - 1]
            candidate = prev + ai
            if candidate <= m and candidate > current_max:
                current_max = candidate
        # Update dp[t] if any valid candidate was found
        if current_max > 0:
            dp[t] = current_max
        else:
            # If no valid sum, leave it as 0 (but possibly invalid)
            pass  # Keep it as 0, but need to check against M later

    # Collect all possible dp values and find the maximum <= m
    max_score = 0
    for t in range(k + 1):
        if dp[t] <= m and dp[t] > max_score:
            max_score = dp[t]
    print(max_score)
0