-
Notifications
You must be signed in to change notification settings - Fork 0
/
SherArray.cpp
41 lines (40 loc) · 1007 Bytes
/
SherArray.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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main() {
int t;
cin >> t;
for(int i = 0; i < t; i++) {
int n;
cin >> n;
long long int A[n];
long long int sum[n]; // sum till ith index
for(int j = 0; j < n; j++) {
cin >> A[j];
if(j)
sum[j] = sum[j - 1] + A[j];
else
sum[j] = A[j];
}
if(n == 1)
cout << "YES" << endl;
else if (n == 2)
cout << "NO" << endl;
else {
bool found = false;
for(int j = 1; j < n; j++)
if(sum[j - 1] == sum[n - 1] - sum[j]) { // sum till j-1 = sum of all - sum till that point
cout << "YES" << endl;
found |= true;
break;
}
if(!found)
cout << "NO" << endl;
}
}
return 0;
}