結果

問題 No.2329 Nafmo、イカサマをする
ユーザー gew1fw
提出日時 2025-06-12 18:18:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 986 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 81,948 KB
実行使用メモリ 54,100 KB
最終ジャッジ日時 2025-06-12 18:18:30
合計ジャッジ時間 2,718 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    N, M, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split())) if N > 0 else []
    if N == 0:
        print(0)
        return
    
    # Sort A in descending order to easily pick the maximum possible value
    sorted_A = sorted(A, reverse=True)
    
    def dfs(remaining, current_sum):
        if remaining == 0:
            return current_sum
        max_val = current_sum  # Option to stop drawing
        
        # Find the maximum a that can be added without exceeding M
        max_a = None
        for a in sorted_A:
            if current_sum + a <= M:
                max_a = a
                break
        if max_a is not None:
            next_sum = current_sum + max_a
            candidate = dfs(remaining - 1, next_sum)
            if candidate > max_val:
                max_val = candidate
        return max_val
    
    result = dfs(K, 0)
    print(result)

if __name__ == '__main__':
    main()
0