-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode2143A.cpp
More file actions
46 lines (38 loc) · 775 Bytes
/
Copy pathcode2143A.cpp
File metadata and controls
46 lines (38 loc) · 775 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
40
41
42
43
44
45
46
/*
* Contest : Codeforces
* Problem : 2143A - All Lengths Subtraction
* Link : https://codeforces.com/contest/2143/problem/A
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
bool solve() {
ll n; cin >> n;
vector<ll> v(n);
for (auto &i : v) {
cin >> i;
if (i == n) i--;
}
ll k = 2;
while (k <= n) {
ll cnt = 1, last = 0;
for (int i = 0; i < n - 1; ++i) {
if (v[i] == v[i + 1] && v[i] == n - k + 1) {
v[i]--;
cnt++;
last = i + 1;
}
}
v[last]--;
if (cnt != k) return false;
k++;
}
return true;
}
int main() {
fastio
ll t; cin >> t;
while (t--) cout << (solve() ? "YES" : "NO") << '\n';
return 0;
}