-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewyear.cpp
More file actions
42 lines (36 loc) · 990 Bytes
/
newyear.cpp
File metadata and controls
42 lines (36 loc) · 990 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
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,allzero=1,oneneg=0,sum=0;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
sum+=arr[i];
if(arr[i]!=0){
allzero=0;
if(arr[i]<0)oneneg=1;
}
}
int maxsofar=INT_MIN,maxehere=0,maxsofar1=INT_MIN,maxehere1=0;
for(int i=0;i<n-1;i++){
maxehere1=maxehere1+arr[i];
maxsofar1=max(maxsofar1,maxehere1);
if(maxehere1<0){maxehere1=0;
// f=1;
}
}
for(int i=1;i<n;i++){
maxehere=maxehere+arr[i];
maxsofar=max(maxsofar,maxehere);
if(maxehere<0){maxehere=0;
// f=1;
}
}
if(maxsofar>=sum||maxsofar1>=sum)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
}