結果

問題 No.2812 Plus Minus Blackboard
ユーザー forest3
提出日時 2024-07-25 11:34:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 1,381 ms
コンパイル使用メモリ 165,532 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2025-04-08 23:45:11
合計ジャッジ時間 3,775 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(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 p.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 p.insert(sum);
		}
	}

	cout << ans << endl;
}
0