結果
| 問題 |
No.2812 Plus Minus Blackboard
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-23 01:46:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 893 bytes |
| コンパイル時間 | 180 ms |
| コンパイル使用メモリ | 82,504 KB |
| 実行使用メモリ | 105,344 KB |
| 最終ジャッジ日時 | 2025-06-20 02:18:27 |
| 合計ジャッジ時間 | 5,655 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 WA * 3 |
ソースコード
## 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)
elif a > 0:
heapq.heappush(p_queue,a)
if len(m_array) == 0 and len(p_queue) == 0:
print("Yes")
return
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()