結果

問題 No.2866 yuusaan's Knapsack
ユーザー ニックネームニックネーム
提出日時 2024-08-30 22:05:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,824 KB
実行使用メモリ 90,136 KB
最終ジャッジ日時 2024-08-31 01:28:05
合計ジャッジ時間 5,179 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
64,700 KB
testcase_01 AC 49 ms
63,652 KB
testcase_02 AC 51 ms
63,740 KB
testcase_03 AC 46 ms
61,312 KB
testcase_04 AC 45 ms
60,856 KB
testcase_05 AC 46 ms
61,180 KB
testcase_06 AC 213 ms
85,484 KB
testcase_07 AC 175 ms
83,384 KB
testcase_08 AC 211 ms
85,132 KB
testcase_09 AC 195 ms
86,148 KB
testcase_10 AC 186 ms
83,360 KB
testcase_11 AC 148 ms
82,348 KB
testcase_12 AC 175 ms
83,656 KB
testcase_13 AC 161 ms
84,608 KB
testcase_14 AC 179 ms
83,416 KB
testcase_15 AC 193 ms
84,884 KB
testcase_16 AC 161 ms
83,840 KB
testcase_17 AC 203 ms
86,540 KB
testcase_18 AC 139 ms
82,028 KB
testcase_19 AC 212 ms
86,156 KB
testcase_20 AC 174 ms
83,824 KB
testcase_21 AC 185 ms
83,728 KB
testcase_22 AC 171 ms
83,588 KB
testcase_23 AC 220 ms
85,816 KB
testcase_24 AC 161 ms
83,392 KB
testcase_25 AC 196 ms
85,932 KB
testcase_26 AC 121 ms
90,136 KB
testcase_27 AC 50 ms
62,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
wv = []; k += 10000; z = 998244353
for _ in range(n):
    v,w = map(int,input().split())
    wv.append((w,v))
dp = [[-10**9,0]]*(20001); dp[10000] = [0,1]
for w,v in sorted(wv):
    eq = [[-10**9,0]]*(20001)
    for i,(s,c) in enumerate(dp):
        if s==-10**9 or i+w>k: continue
        if s+v>eq[i+w][0]: eq[i+w] = [s+v,c]
        elif s+v==eq[i+w][0]: eq[i+w][1] += c
    for i in range(20001):
        if dp[i][0]==eq[i][0]: dp[i][1] += eq[i][1]
        else: dp[i] = max(dp[i],eq[i])
x = y = 0
for s,c in dp:
    if s>x: x,y = s,c
    elif s==x: y += c
print(x,y%z)
0