結果

問題 No.1872 Dictionary Order
ユーザー titiatitia
提出日時 2022-03-13 00:04:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,527 ms / 2,000 ms
コード長 716 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 11,928 KB
実行使用メモリ 41,836 KB
最終ジャッジ日時 2023-10-19 12:39:45
合計ジャッジ時間 20,806 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,444 ms
41,836 KB
testcase_01 AC 36 ms
10,344 KB
testcase_02 AC 701 ms
24,940 KB
testcase_03 AC 125 ms
12,268 KB
testcase_04 AC 1,107 ms
33,652 KB
testcase_05 AC 55 ms
10,752 KB
testcase_06 AC 487 ms
20,452 KB
testcase_07 AC 264 ms
15,436 KB
testcase_08 AC 33 ms
10,264 KB
testcase_09 AC 207 ms
14,152 KB
testcase_10 AC 378 ms
17,548 KB
testcase_11 AC 653 ms
24,148 KB
testcase_12 AC 159 ms
13,060 KB
testcase_13 AC 174 ms
13,424 KB
testcase_14 AC 643 ms
23,356 KB
testcase_15 AC 809 ms
26,524 KB
testcase_16 AC 57 ms
10,816 KB
testcase_17 AC 408 ms
18,076 KB
testcase_18 AC 456 ms
19,924 KB
testcase_19 AC 339 ms
16,492 KB
testcase_20 AC 209 ms
14,116 KB
testcase_21 AC 552 ms
21,244 KB
testcase_22 AC 1,435 ms
34,972 KB
testcase_23 AC 468 ms
19,396 KB
testcase_24 AC 323 ms
16,228 KB
testcase_25 AC 775 ms
24,148 KB
testcase_26 AC 300 ms
16,276 KB
testcase_27 AC 731 ms
23,620 KB
testcase_28 AC 1,181 ms
31,540 KB
testcase_29 AC 1,327 ms
33,916 KB
testcase_30 AC 55 ms
11,180 KB
testcase_31 AC 1,527 ms
37,348 KB
testcase_32 AC 29 ms
10,132 KB
testcase_33 AC 29 ms
10,132 KB
testcase_34 AC 30 ms
10,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
A=list(map(int,input().split()))
P=list(map(int,input().split()))

DP=[[0]*(M+1) for i in range(N+1)]
DP[N][M]=1

for i in range(N-1,-1,-1):
    a=A[i]
    for j in range(M+1):
        if DP[i+1][j]==1:
            DP[i][j]=1
            if j-a>=0:
                DP[i][j-a]=1

Q=[(P[i],i) for i in range(N)]
Q.sort()

now=0
last=-1
ANS=[]
while now!=M:
    for _,i in Q:
        if i<=last:
            continue
        a=A[i]
        if now+a<=M and DP[i+1][now+a]==1:
            ANS.append(i+1)
            now+=a
            last=i
            break
    else:
        break

if now==M:
    print(len(ANS))
    print(*ANS)
else:
    print(-1)
0