結果

問題 No.1570 Blocks
ユーザー H3PO4H3PO4
提出日時 2022-11-29 08:16:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 567 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 28,800 KB
最終ジャッジ日時 2024-04-16 04:16:07
合計ジャッジ時間 12,991 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,496 KB
testcase_01 AC 31 ms
10,624 KB
testcase_02 AC 203 ms
22,648 KB
testcase_03 AC 361 ms
25,676 KB
testcase_04 AC 174 ms
21,092 KB
testcase_05 AC 180 ms
21,612 KB
testcase_06 AC 265 ms
21,940 KB
testcase_07 AC 50 ms
12,160 KB
testcase_08 AC 340 ms
24,992 KB
testcase_09 AC 399 ms
27,744 KB
testcase_10 AC 214 ms
24,120 KB
testcase_11 AC 235 ms
25,768 KB
testcase_12 AC 408 ms
28,148 KB
testcase_13 AC 270 ms
27,936 KB
testcase_14 AC 278 ms
28,572 KB
testcase_15 AC 132 ms
18,556 KB
testcase_16 AC 278 ms
28,320 KB
testcase_17 AC 178 ms
17,920 KB
testcase_18 AC 227 ms
24,840 KB
testcase_19 AC 177 ms
18,176 KB
testcase_20 AC 137 ms
18,412 KB
testcase_21 AC 313 ms
23,596 KB
testcase_22 AC 32 ms
10,496 KB
testcase_23 AC 32 ms
10,752 KB
testcase_24 AC 31 ms
10,496 KB
testcase_25 AC 32 ms
10,752 KB
testcase_26 AC 32 ms
10,496 KB
testcase_27 AC 31 ms
10,496 KB
testcase_28 AC 33 ms
10,752 KB
testcase_29 AC 32 ms
10,624 KB
testcase_30 AC 32 ms
10,496 KB
testcase_31 AC 31 ms
10,496 KB
testcase_32 AC 405 ms
28,004 KB
testcase_33 AC 417 ms
28,436 KB
testcase_34 AC 264 ms
27,004 KB
testcase_35 AC 417 ms
27,976 KB
testcase_36 AC 276 ms
27,600 KB
testcase_37 AC 394 ms
27,316 KB
testcase_38 AC 397 ms
27,776 KB
testcase_39 AC 280 ms
28,472 KB
testcase_40 AC 275 ms
27,800 KB
testcase_41 AC 410 ms
27,880 KB
testcase_42 AC 284 ms
28,668 KB
testcase_43 AC 287 ms
28,672 KB
testcase_44 AC 291 ms
28,800 KB
testcase_45 AC 288 ms
28,796 KB
testcase_46 AC 425 ms
28,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import heapq

input = sys.stdin.buffer.readline


def solve(N, blocks):
    blocks.sort(key=lambda x: x[0] + x[1])
    S = sum(a for a, _ in blocks)
    h = []
    for _ in range(N):
        while blocks and blocks[-1][0] + blocks[-1][1] >= S:
            a, b = blocks.pop()
            heapq.heappush(h, -a)
        if h:
            a = -heapq.heappop(h)
            S -= a
        else:
            return False
    return True


N = int(input())
blocks = [tuple(map(int, input().split())) for _ in range(N)]
print("Yes" if solve(N, blocks) else "No")
0