結果

問題 No.1872 Dictionary Order
ユーザー lilictakalilictaka
提出日時 2022-05-11 22:04:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 959 bytes
コンパイル時間 992 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 109,300 KB
最終ジャッジ日時 2023-09-26 13:25:21
合計ジャッジ時間 7,875 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 244 ms
109,300 KB
testcase_01 AC 78 ms
76,076 KB
testcase_02 AC 151 ms
90,756 KB
testcase_03 AC 91 ms
76,448 KB
testcase_04 AC 182 ms
89,664 KB
testcase_05 AC 82 ms
76,252 KB
testcase_06 AC 134 ms
87,636 KB
testcase_07 AC 107 ms
76,860 KB
testcase_08 AC 81 ms
76,652 KB
testcase_09 AC 93 ms
76,556 KB
testcase_10 AC 109 ms
76,720 KB
testcase_11 AC 156 ms
89,320 KB
testcase_12 AC 98 ms
76,688 KB
testcase_13 AC 90 ms
76,584 KB
testcase_14 AC 149 ms
89,548 KB
testcase_15 AC 166 ms
89,260 KB
testcase_16 AC 83 ms
76,788 KB
testcase_17 AC 111 ms
76,888 KB
testcase_18 AC 130 ms
87,044 KB
testcase_19 AC 101 ms
76,832 KB
testcase_20 AC 95 ms
76,616 KB
testcase_21 AC 141 ms
88,456 KB
testcase_22 AC 206 ms
89,752 KB
testcase_23 AC 141 ms
86,776 KB
testcase_24 AC 115 ms
76,764 KB
testcase_25 AC 160 ms
90,976 KB
testcase_26 AC 107 ms
76,508 KB
testcase_27 AC 161 ms
90,736 KB
testcase_28 AC 190 ms
89,984 KB
testcase_29 AC 200 ms
89,792 KB
testcase_30 AC 85 ms
76,044 KB
testcase_31 AC 235 ms
104,652 KB
testcase_32 AC 72 ms
71,580 KB
testcase_33 AC 72 ms
71,208 KB
testcase_34 AC 78 ms
76,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)))


0