-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathA_Directional_Increase.cpp
More file actions
51 lines (46 loc) · 1.45 KB
/
A_Directional_Increase.cpp
File metadata and controls
51 lines (46 loc) · 1.45 KB
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
#include <bits/stdc++.h>
using namespace std;
//----------------------------------------------------------------//
// definitions //
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define endl '\n'
//----------------------------------------------------------------//
// preDefined functions//
//----------------------------------------------------------------//
//data types//
//----------------------------------------------------------------//
// helper functions //
//----------------------------------------------------------------//
// solve function//
void solve() {
long long size;cin >> size;
vector<long long>data( size );
for (auto& it : data)cin >> it;
if (all_of( all( data ), []( long long x ) { return x == 0; } )) { cout << "Yes" << endl;return; }
long long actualLastIndex = size - 1;
while (data[ actualLastIndex ] == 0)actualLastIndex--;
long long sum = 0;
for (long long i = 0;i < actualLastIndex;i++) {
sum += data[ i ];
if (sum <= 0) {
cout << "No" << endl;
return;
}
}
if (sum + data[ actualLastIndex ] == 0)
cout << "Yes" << endl;
else cout << "No" << endl;
}
//----------------------------------------------------------------//
// main function//
int main() {
ios_base::sync_with_stdio( false );
cin.tie( NULL );
cout.tie( NULL );
long long test = 1;
cin >> test;
while (test--) {
solve();
}
}