結果

問題 No.2812 Plus Minus Blackboard
ユーザー LyricalMaestro
提出日時 2024-10-23 01:44:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 82,920 KB
実行使用メモリ 106,656 KB
最終ジャッジ日時 2025-04-08 23:45:44
合計ジャッジ時間 4,166 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import heapq

def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    m_array = []
    p_queue = []
    for a in A:
        if a < 0:
            m_array.append(a)
        else:
            heapq.heappush(p_queue,a)

    m_index = len(m_array) - 1

    while m_index >= 0:
        m = m_array[m_index]
        while m < 0 and len(p_queue) > 0:
            a = heapq.heappop(p_queue)
            m += a
        if m >= 0:
            heapq.heappush(p_queue, m)
            m_index -= 1
        else:
            break
    
    if m_index == -1 and len(p_queue) == 1:
        print("Yes")
    elif m_index == 0 and len(p_queue) == 0:
        print("Yes")
    else:
        print("No")


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