結果

問題 No.1583 Building Blocks
ユーザー H3PO4H3PO4
提出日時 2023-07-31 08:40:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 526 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 10,808 KB
実行使用メモリ 8,388 KB
最終ジャッジ日時 2023-10-12 03:06:34
合計ジャッジ時間 3,466 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,788 KB
testcase_01 AC 16 ms
7,832 KB
testcase_02 AC 17 ms
7,812 KB
testcase_03 AC 31 ms
7,816 KB
testcase_04 AC 17 ms
7,908 KB
testcase_05 AC 16 ms
7,840 KB
testcase_06 AC 29 ms
7,784 KB
testcase_07 AC 34 ms
7,816 KB
testcase_08 AC 16 ms
7,796 KB
testcase_09 AC 61 ms
8,216 KB
testcase_10 AC 16 ms
7,820 KB
testcase_11 AC 16 ms
7,844 KB
testcase_12 AC 43 ms
8,380 KB
testcase_13 AC 56 ms
8,192 KB
testcase_14 AC 28 ms
7,836 KB
testcase_15 AC 41 ms
8,316 KB
testcase_16 AC 51 ms
8,208 KB
testcase_17 AC 66 ms
8,248 KB
testcase_18 AC 24 ms
7,820 KB
testcase_19 AC 121 ms
8,216 KB
testcase_20 AC 35 ms
7,956 KB
testcase_21 AC 34 ms
7,784 KB
testcase_22 AC 38 ms
7,820 KB
testcase_23 AC 21 ms
7,908 KB
testcase_24 AC 106 ms
8,240 KB
testcase_25 AC 16 ms
7,908 KB
testcase_26 AC 128 ms
8,388 KB
testcase_27 AC 39 ms
7,812 KB
testcase_28 AC 144 ms
8,244 KB
testcase_29 AC 28 ms
7,884 KB
testcase_30 AC 20 ms
7,832 KB
testcase_31 AC 44 ms
8,240 KB
testcase_32 AC 28 ms
7,748 KB
testcase_33 AC 67 ms
8,252 KB
testcase_34 AC 16 ms
7,948 KB
testcase_35 AC 30 ms
7,764 KB
testcase_36 AC 49 ms
8,220 KB
testcase_37 AC 19 ms
7,816 KB
testcase_38 AC 16 ms
7,856 KB
testcase_39 AC 16 ms
7,808 KB
testcase_40 AC 17 ms
7,844 KB
testcase_41 AC 16 ms
7,944 KB
testcase_42 AC 16 ms
7,844 KB
testcase_43 AC 16 ms
7,840 KB
testcase_44 AC 16 ms
7,812 KB
testcase_45 AC 15 ms
7,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(N, blocks):
    blocks.sort(key=lambda x: x[0] + x[1])

    INF = 10 ** 18
    dp = [INF] * (N + 1)
    dp[0] = 0
    for i, (w, s) in enumerate(blocks):
        new_dp = dp.copy()
        for n in range(N):
            if dp[n] <= s:
                new_dp[n + 1] = min(dp[n] + w, new_dp[n + 1])
        dp = new_dp
    for n in range(N, -1, -1):
        if dp[n] != INF:
            return n
    return 0


N = int(input())
blocks = list(tuple(map(int, input().split())) for _ in range(N))
print(solve(N, blocks))
0