結果

問題 No.1583 Building Blocks
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-07-02 22:55:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 965 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 76,996 KB
最終ジャッジ日時 2023-10-12 03:04:16
合計ジャッジ時間 6,628 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,276 KB
testcase_01 AC 76 ms
71,476 KB
testcase_02 AC 77 ms
71,264 KB
testcase_03 AC 97 ms
76,588 KB
testcase_04 AC 86 ms
76,140 KB
testcase_05 AC 83 ms
76,324 KB
testcase_06 AC 92 ms
76,524 KB
testcase_07 AC 95 ms
76,732 KB
testcase_08 AC 85 ms
76,248 KB
testcase_09 AC 106 ms
76,668 KB
testcase_10 AC 84 ms
76,072 KB
testcase_11 AC 79 ms
71,612 KB
testcase_12 AC 98 ms
76,584 KB
testcase_13 AC 102 ms
76,428 KB
testcase_14 AC 94 ms
76,336 KB
testcase_15 AC 96 ms
76,524 KB
testcase_16 AC 100 ms
76,476 KB
testcase_17 AC 100 ms
76,580 KB
testcase_18 AC 89 ms
76,076 KB
testcase_19 AC 109 ms
76,996 KB
testcase_20 AC 93 ms
76,720 KB
testcase_21 AC 95 ms
76,388 KB
testcase_22 AC 94 ms
76,604 KB
testcase_23 AC 88 ms
76,104 KB
testcase_24 AC 102 ms
76,504 KB
testcase_25 AC 78 ms
71,604 KB
testcase_26 AC 105 ms
76,672 KB
testcase_27 AC 93 ms
76,716 KB
testcase_28 AC 112 ms
76,992 KB
testcase_29 AC 97 ms
76,476 KB
testcase_30 AC 90 ms
76,384 KB
testcase_31 AC 99 ms
76,284 KB
testcase_32 AC 94 ms
76,568 KB
testcase_33 AC 105 ms
76,652 KB
testcase_34 AC 79 ms
71,348 KB
testcase_35 AC 94 ms
76,364 KB
testcase_36 AC 101 ms
76,568 KB
testcase_37 AC 87 ms
76,292 KB
testcase_38 AC 78 ms
71,340 KB
testcase_39 AC 78 ms
71,520 KB
testcase_40 AC 77 ms
71,092 KB
testcase_41 AC 78 ms
71,344 KB
testcase_42 AC 77 ms
71,252 KB
testcase_43 AC 83 ms
71,272 KB
testcase_44 AC 78 ms
71,384 KB
testcase_45 AC 77 ms
71,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


"""

https://yukicoder.me/problems/no/1583

https://atcoder.jp/contests/cf17-final/tasks/cf17_final_d

全て置けるかの判定を考える
H+Pで昇順ソート
後ろから見ていって、その時点での座布団がH+P以下なら○ だめならX
を付けてPを引く
を繰り返し、全て○なら全員置ける(丸の数以上の答えであることが確定する)

あとは前から見ていってdp?
dp[i][j] = i人目まで見てj人置いた時の最小の枚数
→H+Pでソートするのが正しいなら絶対おkなんだが…

"""

N = int(input())

SHP = []

for i in range(N):

    p,h = map(int,input().split())
    SHP.append( (h+p,h,p) )

SHP.sort()

dp = [float("inf")] * (N+1)
dp[0] = 0

for i in range(N):

    s,h,p = SHP[i]

    for j in range(N-1,-1,-1):

        if dp[j] <= h:
            dp[j+1] = min(dp[j+1] , dp[j] + p)

ans = 0
for i in range(N+1):
    if dp[i] != float("inf"):
        ans = i
print (ans)
0