結果
問題 | No.1872 Dictionary Order |
ユーザー |
|
提出日時 | 2022-03-11 22:28:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 188 ms / 2,000 ms |
コード長 | 793 bytes |
コンパイル時間 | 347 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 107,904 KB |
最終ジャッジ日時 | 2024-09-19 08:42:20 |
合計ジャッジ時間 | 4,571 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
N,M = map(int,input().split())A = list(map(int,input().split()))P = list(map(int,input().split()))dp = [[0] * (M + 1) for _ in range(N+1)]dp[N-1][0] = 1dp[N-1][A[-1]] = 1dp[-1][0] = 1for i in reversed(range(N-1)):for j in range(M+1):dp[i][j] = dp[i+1][j]for j in range(M+1):if j + A[i] <= M:if dp[i+1][j]:dp[i][j+A[i]] = 1else:breakimport sysif dp[0][-1] == 0:print(-1)exit()ans = []now = Mleft = -1while now:_min = 10000index = -1for i in range(left+1,N):if A[i] <= now and dp[i+1][now-A[i]]:if P[i] < _min:_min = P[i]index = ians.append(index+1)now -= A[index]left = indexprint(len(ans))print(*ans)