fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5. int n;
  6. cin >> n;
  7. vector<int> a(n);
  8. for (int i = 0; i < n; i++) cin >> a[i];
  9. for (int i = 0; i < n - 1; i++) {
  10. if (a[i] <= a[i + 1]) {
  11. a[i + 1] -= a[i];
  12. } else {
  13. cout << "NO" << endl;
  14. return;
  15. }
  16. }
  17. cout << "YES" << endl;
  18. }
  19.  
  20. int main() {
  21. int t;
  22. cin >> t;
  23. while (t--) solve();
  24. }
Success #stdin #stdout 0s 5288KB
stdin
5
5
1 2 3 4 5
4
4 3 2 1
4
4 5 2 3
8
4 5 4 5 4 5 4 5
9
9 9 8 2 4 4 3 5 3
stdout
YES
NO
YES
YES
NO