結果

問題 No.1872 Dictionary Order
ユーザー hir355hir355
提出日時 2022-03-11 23:10:44
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 619 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 107,184 KB
最終ジャッジ日時 2023-10-19 12:37:51
合計ジャッジ時間 4,193 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 178 ms
107,184 KB
testcase_01 AC 42 ms
59,676 KB
testcase_02 AC 94 ms
90,444 KB
testcase_03 AC 51 ms
66,288 KB
testcase_04 AC 106 ms
90,264 KB
testcase_05 AC 47 ms
61,720 KB
testcase_06 AC 83 ms
85,812 KB
testcase_07 AC 60 ms
68,416 KB
testcase_08 AC 50 ms
62,004 KB
testcase_09 AC 54 ms
66,132 KB
testcase_10 AC 64 ms
70,392 KB
testcase_11 AC 89 ms
89,496 KB
testcase_12 AC 59 ms
66,372 KB
testcase_13 AC 54 ms
66,136 KB
testcase_14 AC 88 ms
88,844 KB
testcase_15 AC 98 ms
90,420 KB
testcase_16 AC 51 ms
62,172 KB
testcase_17 AC 67 ms
72,536 KB
testcase_18 AC 69 ms
73,092 KB
testcase_19 AC 66 ms
70,412 KB
testcase_20 AC 54 ms
66,284 KB
testcase_21 AC 75 ms
73,792 KB
testcase_22 AC 128 ms
90,788 KB
testcase_23 AC 91 ms
84,808 KB
testcase_24 AC 65 ms
70,324 KB
testcase_25 AC 101 ms
89,552 KB
testcase_26 AC 65 ms
70,324 KB
testcase_27 AC 104 ms
89,128 KB
testcase_28 AC 119 ms
90,920 KB
testcase_29 AC 126 ms
90,872 KB
testcase_30 AC 51 ms
61,740 KB
testcase_31 AC 129 ms
90,792 KB
testcase_32 AC 35 ms
53,336 KB
testcase_33 AC 36 ms
53,336 KB
testcase_34 AC 43 ms
59,672 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[-1][0] = 1
for i in range(n, 0, -1):
    for j in range(m + 1):
        if j + a[i - 1] <= m:
            dp[i - 1][j + a[i - 1]] |= dp[i][j]
        dp[i - 1][j] |= dp[i][j]
if not dp[0][m]:
    print(-1)
    exit(0)
idx = -1
ans = []
while m > 0:
    mi = -1
    for i in range(idx + 1, n):
        if m >= a[i] and dp[i + 1][m - a[i]] and (mi == -1 or p[i] < p[mi]):
            mi = i
    m -= a[mi]
    idx = mi
    ans.append(idx + 1)
print(len(ans))
print(*ans)
0