-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
39 lines (37 loc) · 685 Bytes
/
Copy pathD.cpp
File metadata and controls
39 lines (37 loc) · 685 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
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define ERR(...) fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n")
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
int rlast = 0, llast = a[0];
bool ok = true;
for (int i = 1; i < n; ++i) {
if (a[i] < rlast) {
ok = false;
break;
}
a[i] -= rlast;
if (a[i] > llast) {
rlast += a[i] - llast;
a[i] = llast;
}
llast = a[i];
}
if (!ok) {
puts("NO");
} else {
puts("YES");
}
}
return 0;
}