-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1698_C.cpp
More file actions
55 lines (49 loc) · 1.26 KB
/
1698_C.cpp
File metadata and controls
55 lines (49 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pii = pair<int,int>;
void solve(){
int N; cin >> N;
vector<int> negative;
vector<int> zero;
vector<int> positive;
for (int i = 0; i < N; i++) {
int a; cin >> a;
if (a < 0) negative.push_back(a);
else if (a == 0) zero.push_back(a);
else positive.push_back(a);
}
if (negative.size() > 2 || positive.size() > 2) {
cout << "NO";
return;
}
vector<int> f;
for (auto p : positive) f.push_back(p);
for (auto n : negative) f.push_back(n);
if (zero.size() > 0) f.push_back(0);
if (zero.size() > 1) f.push_back(0);
N = f.size();
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
for (int k = j + 1; k < N; k++) {
if (i == j && j == k) continue;
if (find(f.begin(), f.end(), f[i]+f[j]+f[k]) == f.end()) {
cout << "NO";
return;
}
}
}
}
cout << "YES";
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int T = 1;
cin >> T;
while (T--) {
solve();
cout << '\n';
}
return 0;
}