-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
61 lines (59 loc) · 1.36 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
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[300005],tmp[300005];
int main()
{
fastio;
long long t,n,i,p;
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<n;i++){
cin>>ara[i];
tmp[i]=ara[i];
}
if(n==1)
cout<<"YES\n";
else if(n==2)
{
if(ara[0]>ara[1])
cout<<"NO\n";
else
cout<<"YES\n";
}
else
{
for(i=n-2;i>0;i--)
{
if(ara[i]>ara[i+1])
{
long long dif=ara[i]-ara[i+1];
ara[i]=ara[i+1];
ara[i-1]=ara[i-1]-dif;
}
}
if(ara[0]<=ara[1])
cout<<"YES\n";
else
{
for(i=1;i<n-1;i++)
{
if(ara[i]<ara[i-1])
{
long long dif=ara[i-1]-ara[i];
ara[i]=ara[i-1];
ara[i+1]=ara[i+1]+dif;
}
}
if(ara[n-1]<ara[n-2])
cout<<"NO\n";
else
cout<<"YES\n";
}
}
}
return 0;
}