結果

問題 No.1872 Dictionary Order
ユーザー ああいいああいい
提出日時 2022-03-11 22:28:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 107,452 KB
最終ジャッジ日時 2023-10-19 12:36:50
合計ジャッジ時間 4,527 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
107,452 KB
testcase_01 AC 47 ms
59,512 KB
testcase_02 AC 104 ms
90,520 KB
testcase_03 AC 60 ms
66,336 KB
testcase_04 AC 122 ms
90,268 KB
testcase_05 AC 49 ms
61,560 KB
testcase_06 AC 92 ms
85,856 KB
testcase_07 AC 68 ms
70,504 KB
testcase_08 AC 49 ms
62,032 KB
testcase_09 AC 61 ms
66,172 KB
testcase_10 AC 71 ms
72,484 KB
testcase_11 AC 101 ms
89,712 KB
testcase_12 AC 64 ms
68,480 KB
testcase_13 AC 59 ms
66,160 KB
testcase_14 AC 99 ms
88,888 KB
testcase_15 AC 109 ms
90,440 KB
testcase_16 AC 54 ms
64,264 KB
testcase_17 AC 75 ms
72,624 KB
testcase_18 AC 78 ms
74,020 KB
testcase_19 AC 69 ms
70,452 KB
testcase_20 AC 62 ms
68,380 KB
testcase_21 AC 92 ms
86,600 KB
testcase_22 AC 155 ms
90,792 KB
testcase_23 AC 101 ms
84,972 KB
testcase_24 AC 78 ms
72,420 KB
testcase_25 AC 118 ms
89,716 KB
testcase_26 AC 78 ms
72,420 KB
testcase_27 AC 119 ms
89,216 KB
testcase_28 AC 144 ms
90,944 KB
testcase_29 AC 152 ms
90,868 KB
testcase_30 AC 52 ms
63,784 KB
testcase_31 AC 159 ms
90,796 KB
testcase_32 AC 40 ms
53,396 KB
testcase_33 AC 39 ms
53,396 KB
testcase_34 AC 45 ms
59,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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] = 1
dp[N-1][A[-1]] = 1
dp[-1][0] = 1
for 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]] = 1
        else:
            break
import sys
if dp[0][-1] == 0:
    print(-1)
    exit()
ans = []
now = M
left = -1
while now:
    _min = 10000
    index = -1
    for 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 = i
    ans.append(index+1)
    now -= A[index]
    left = index
print(len(ans))
print(*ans)
0