-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
66 lines (64 loc) · 1.37 KB
/
C.cpp
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
56
57
58
59
60
61
62
63
64
65
66
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[200005];
int main()
{
fastio;
long long t,n,i,pos,neg,zer,j,k,p;
cin>>t;
while(t--)
{
cin>>n;
pos=0;
neg=0;
zer=0;
p=0;
map<long long,long long> mp;
for(i=0;i<n;i++)
{
cin>>ara[i];
if(ara[i]>0)
pos++;
else if(ara[i]<0)
neg++;
else
zer++;
mp[ara[i]]++;
}
if(pos>2 || neg>2)
{
cout<<"NO\n";
continue;
}
sort(ara,ara+n);
vector<long long> vect;
for(i=0;i<n;i++)
{
if(ara[i]<0)
vect.push_back(ara[i]);
if(ara[i]>0)
vect.push_back(ara[i]);
}
if(zer>0)
vect.push_back(0LL);
if(zer>1)
vect.push_back(0LL);
for(i=0;i<vect.size();i++)
{
for(j=i+1;j<vect.size();j++)
{
for(k=j+1;k<vect.size();k++)
{
if(mp[vect[i]+vect[j]+vect[k]]==0)
p=1;
}
}
}
if(p==1)
cout<<"NO\n";
else
cout<<"YES\n";
}
return 0;
}