-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path089-extreme-subtraction.cpp
More file actions
41 lines (40 loc) · 963 Bytes
/
Copy path089-extreme-subtraction.cpp
File metadata and controls
41 lines (40 loc) · 963 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
/*
* Extreme Subtraction [1442A]
* Problem: https://codeforces.com/problemset/problem/1442/A
* Verdict: ACCEPTED Solved: 2023-12-17
* Language: C++20 (GCC 11-64)
* Runtime: 15 ms Memory: 200 KB
* Tags: constructive algorithms, dp, greedy
* Author: BidoTeima
* Source: https://codeforces.com/contest/1442/submission/237662309
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
ll a[n];
for(int i = 0; i < n; i++)cin>>a[i];
ll x = 0;
bool ans = 1;
for(int i = 1; i < n; i++){
if(a[i]>a[i-1]){
x += a[i] - a[i - 1];
}
if(a[i] - x < 0){
ans = 0;
break;
}
}
cout<<(ans?"YES\n":"NO\n");
}
return 0;
}