結果

問題 No.1570 Blocks
ユーザー LyricalMaestro
提出日時 2025-05-05 20:48:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 750 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 93,436 KB
最終ジャッジ日時 2025-05-05 20:48:31
合計ジャッジ時間 11,712 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1570

import heapq

def main():
    N = int(input())
    ab = []
    for _ in range(N):
        a, b = map(int, input().split())
        ab.append((a, b))

    ab_array = []
    for a, b in ab:
        ab_array.append((a + b, a))
    ab_array.sort(key=lambda x: x[0])
    sum_a = 0
    for a, _ in ab:
        sum_a += a

    queue = []
    index = N - 1
    while sum_a > 0:
        while index >= 0 and ab_array[index][0] >= sum_a:
            heapq.heappush(queue, -ab_array[index][1])
            index -= 1

        if len(queue) == 0:
            print("No")
            return
        
        x = heapq.heappop(queue)
        sum_a += x
    
    print("Yes")


    



if __name__ == "__main__":
    main()
0