結果
問題 |
No.2329 Nafmo、イカサマをする
|
ユーザー |
|
提出日時 | 2023-09-01 14:04:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 359 ms / 2,000 ms |
コード長 | 846 bytes |
コンパイル時間 | 338 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 101,868 KB |
最終ジャッジ日時 | 2025-01-03 06:33:46 |
合計ジャッジ時間 | 5,632 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#int(input()) #map(int, input().split()) #list(map(int, input().split())) N, M, K = map(int, input().split()) A = list(map(int, input().split())) from itertools import product from bisect import bisect_right ans = 0 if 1 <= K <= 3: for i in range(K): for x in product(A, repeat=i+1): s = sum(x) if s <= M: ans = max(ans, s) else: A.append(0) s2 = set() s3 = set() for i in range(3): for x in product(A, repeat=i+1): s = sum(x) if i < 2: s2.add(s) if i < 3: s3.add(s) if K == 4: u = A elif K == 5: u = s2 else: u = s3 s3 = sorted(s3) for x in u: t = bisect_right(s3, M-x) if t != 0: ans = max(ans, x+s3[t-1]) print(ans)