結果
問題 | No.1872 Dictionary Order |
ユーザー |
![]() |
提出日時 | 2022-05-11 22:04:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 204 ms / 2,000 ms |
コード長 | 959 bytes |
コンパイル時間 | 148 ms |
コンパイル使用メモリ | 82,056 KB |
実行使用メモリ | 108,032 KB |
最終ジャッジ日時 | 2024-07-19 07:46:50 |
合計ジャッジ時間 | 4,573 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
N,M = map(int,input().split()) A = list(map(int,input().split())) P = list(map(int,input().split())) board = [] for i in range(N): board.append((P[i],i)) board.sort(key=lambda x:x[0]) dp = [[False] * (M+1) for _ in range(N)] dp[N-1][0] = True dp[N-1][A[-1]] = True for i in reversed(range(1,N)): for m in range(M+1): if dp[i][m]: if m + A[i-1] <= M: dp[i-1][m + A[i-1]] = dp[i][m] dp[i-1][m] = dp[i][m] cur = - 1 ANS = [] while M: for p,index in board: if index+1 < N and M-A[index] >= 0 and dp[index+1][M-A[index]] and cur < index: ANS.append(index) M-=A[index] cur = index break elif index == N -1: if dp[index][M]: ANS.append(index) M-= A[index] break else: break if ANS == []: print(-1) else: print(len(ANS)) print(*list(map(lambda x:x+1,ANS)))