結果
問題 |
No.1861 Required Number
|
ユーザー |
|
提出日時 | 2022-03-04 21:58:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 441 ms / 2,500 ms |
コード長 | 700 bytes |
コンパイル時間 | 334 ms |
コンパイル使用メモリ | 82,128 KB |
実行使用メモリ | 155,620 KB |
最終ジャッジ日時 | 2024-07-18 22:51:04 |
合計ジャッジ時間 | 23,376 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 TLE * 3 MLE * 1 |
ソースコード
import sys input = sys.stdin.readline from collections import * N, K = map(int, input().split()) A = list(map(int, input().split())) dp1 = [False]*(K+1) dp1[0] = True dp2 = [[False]*(K+1) for _ in range(N+1)] dp2[0][0] = True for i in range(N): for j in range(K+1): if dp2[i][j]: dp2[i+1][j] = True if j+A[N-1-i]<=K: dp2[i+1][j+A[N-1-i]] = True if not dp2[N][K]: exit(print(-1)) ans = 0 for i in range(N): for j in range(K+1): if dp1[j] and dp2[N-1-i][K-j]: break else: ans += 1 for j in range(K, -1, -1): if dp1[j] and j+A[i]<=K: dp1[j+A[i]] = True print(ans)