-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy path1692F-3SUM.cpp
39 lines (30 loc) · 1 KB
/
1692F-3SUM.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
#include <cstdio>
int main(){
const int B = 10;
long t; scanf("%ld", &t);
while(t--){
long n; scanf("%ld", &n);
long cnt[B] = {0};
for(long p = 0; p < n; p++){
long x; scanf("%ld", &x);
++cnt[x % B];
}
bool res(false);
for(long p = 0; !res && p < B; p++){
for(long q = p; !res && q < B; q++){
for(long r = q; !res && r < B; r++){
if((p + q + r) % 10 != 3){continue;}
--cnt[p]; --cnt[q]; --cnt[r];
if(cnt[p] >= 0 && cnt[q] >= 0 && cnt[r] >= 0){res = true;}
++cnt[p]; ++cnt[q]; ++cnt[r];
/*
printf("Testing: %ld %ld %ld SUM:%ld\n", p, q, r, p + q + r);
printf("Counts: "); for(long u = 0; u < B; u++){printf("%ld ", cnt[u]);}
puts("");
*/
}
}
}
puts(res ? "YES" : "NO");
}
}