-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
48 lines (38 loc) · 807 Bytes
/
test.cpp
File metadata and controls
48 lines (38 loc) · 807 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int tt = 0; tt < t; tt++) {
int n;
cin>>n;
int arr[n];
long long sum=0;
for(int i=0;i<n;i++){
cin>>arr[i];
sum+=arr[i];
}
long long curr=0;
long long ans=0;
int k=0,l=0;
for(int i=0;i<n;i++){
curr+=arr[i];
if(curr>ans){
ans=curr;
l = i;
}
if(curr<=0){
curr=0;
k = i + 1;
l = i + 1;
}
}
// cout<<sum<<" "<<ans<<endl;
// cout<<k<<" "<<l<<endl;
if(sum==ans && ( k==0 && l==n-1 ) )
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}