-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforces1200B.cpp
More file actions
42 lines (42 loc) · 934 Bytes
/
Codeforces1200B.cpp
File metadata and controls
42 lines (42 loc) · 934 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,n,m,k,i,j,cnt=0;
cin>>t;
while(t--)
{
cin>>n>>m>>k;
int a[n+2];
memset(a,0,sizeof(a));
for(i=1;i<=n;i++) cin>>a[i];
bool flag=0;
for(i=1;i<n;i++)
{
if(a[i]==a[i+1])
{
m+=(min(a[i],k));
}
else if(a[i]<a[i+1])
{
j=max(0,a[i+1]-k);
if(j>a[i]){
m-=(j-a[i]);
if(m<0)
{
flag=1;
break;
}
}
else {
m+=a[i]-j;
}
}
else {
m+=a[i]-max(0,a[i+1]-k);
}
}
if(flag) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
}