aboutsummaryrefslogtreecommitdiff
path: root/contests/Round#788/A(2_pointers).cpp
blob: 5d56719e0083bcfcee657465031eee79e318a445 (plain)
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
#include<bits/stdc++.h>
using namespace std;
int main () {
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto &x : v) {
      cin >> x;
    }
    int l = 0, r = v.size() - 1;
    while(r > l) {
      while(v[l] < 0) {
        l++;
      }
      while(v[r] > 0) {
        r--;
      }
      if(l > r) break;
      v[l] = -v[l];
      v[r] = -v[r];
    }
    cout << (is_sorted(v.begin(), v.end()) ? "YES" : "NO");
  }
}