-
Notifications
You must be signed in to change notification settings - Fork 0
/
kuruk14.cpp
39 lines (37 loc) · 829 Bytes
/
kuruk14.cpp
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
#include <iostream>
using namespace std;
int main() {
freopen("input.txt", "r", stdin);
int test_cases, len;
cin >> test_cases;
while (test_cases--) {
cin >> len;
int ele[len], intended_sum = 0, actual_sum = 0;
bool marked[len], visited[len], flagged = false;
memset(marked, false, sizeof(marked));
memset(visited, false, sizeof(visited));
for (int i = 0; i < len; ++i) {
cin >> ele[i];
if (ele[i] >= len)
flagged = true;
else
marked[ele[i]] = true;
}
if (flagged)
cout << "NO" << endl;
else {
for (int i = 0; i < len; ++i) {
if (!marked[i])
intended_sum += i;
if (visited[ele[i]])
actual_sum += len-ele[i]-1;
else
visited[ele[i]] = true;
}
if (actual_sum == intended_sum)
cout << "YES" << endl;
else cout << "NO" << endl;
}
}
return 0;
}