diff --git a/hackerrank.new.year.chaos.cpp b/hackerrank.new.year.chaos.cpp new file mode 100644 index 0000000..f83143d --- /dev/null +++ b/hackerrank.new.year.chaos.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +int main() { + bool chaotic = false; + int t, n, bribes = 0; + cin >> t; + while (t--) { + cin >> n; + vector 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; +}