solved hackerrank's new year chaos

Signed-off-by: ayham <altffour@protonmail.com>
This commit is contained in:
ayham 2021-05-11 07:42:23 +03:00
parent 193923de4e
commit 5f7f8dbecf
No known key found for this signature in database
GPG Key ID: 81D38F7122AFCC94
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
bool chaotic = false;
int t, n, bribes = 0;
cin >> t;
while (t--) {
cin >> n;
vector<int> line(n);
for (int i = 0; i < n; i++) cin >> line[i];
for (int i = line.size()-1; i >= 0; i--) {
if (line[i]-(i+1) > 2) {
cout << "Too chaotic" << endl; chaotic = true;
break;
}
for (int j = max(0, line[i] - 2); j < i; j++)
if (line[j] > line[i]) bribes++;
}
if (!chaotic) cout << bribes << endl;
chaotic = false;
bribes = 0;
}
return 0;
}