結果
| 問題 |
No.2812 Plus Minus Blackboard
|
| コンテスト | |
| ユーザー |
forest3
|
| 提出日時 | 2025-05-28 20:51:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 299 ms / 2,000 ms |
| コード長 | 1,165 bytes |
| コンパイル時間 | 1,742 ms |
| コンパイル使用メモリ | 165,140 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2025-06-20 03:03:40 |
| 合計ジャッジ時間 | 4,742 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
int main() {
int N;
cin >> N;
multiset<int> p, m;
ll s = 0;
rep(i, N) {
int a;
cin >> a;
if(a < 0) m.insert(a);
if(a > 0) p.insert(a);
s += a;
}
string ans = "No";
if(m.size() + p.size() <= 1) ans = "Yes";
else if(s < 0) {
while(1) {
if(p.size() + m.size() == 1) {
ans = "Yes";
break;
}
if(p.size() == 0) break;
int pn = *prev(p.end());
p.erase(prev(p.end()));
int mn = *prev(m.end());
m.erase(prev(m.end()));
int sum = pn + mn;
if(sum < 0) m.insert(sum);
else if(sum > 0) p.insert(sum);
else {
if(p.size() <= m.size()) p.insert(sum);
else m.insert(sum);
}
}
}
else {
while(1) {
if(p.size() + m.size() == 1) {
ans = "Yes";
break;
}
if(m.size() == 0) break;
int pn = *p.begin();
p.erase(p.begin());
int mn = *m.begin();
m.erase(m.begin());
int sum = pn + mn;
if(sum < 0) m.insert(sum);
else if(sum > 0) p.insert(sum);
else {
if(m.size() <= p.size() ) m.insert(sum);
else p.insert(sum);
}
}
}
cout << ans << endl;
}
forest3