-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2060D.cpp
More file actions
47 lines (38 loc) · 1.17 KB
/
2060D.cpp
File metadata and controls
47 lines (38 loc) · 1.17 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
// coded by Cocane
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (int i = 0; i < n; i++)
#define read(a) for (auto &i : a) cin >> i
typedef vector<int> vi;
// Function to check if the array can be reduced to a sorted sequence
string canReduceToSorted(int n, vi &v) {
// Iterating through the array and checking the condition
for (int i = 0; i < n - 1; i++) {
if (v[i] > v[i + 1]) {
return "NO"; // If condition breaks, return NO
} else {
v[i + 1] -= v[i]; // Reduce the next element
}
}
return "YES"; // If all conditions pass, return YES
}
// Driver function to handle multiple test cases
void solveTestCases() {
int t;
cin >> t; // Number of test cases
while (t--) {
int n;
cin >> n; // Size of the array
vi v(n); // Array to store values
read(v); // Read the array
// Output the result for the current test case
cout << canReduceToSorted(n, v) << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
solveTestCases();
return 0;
}