-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
NewYearChaos.java
35 lines (32 loc) · 913 Bytes
/
NewYearChaos.java
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static void minimumBribes(int[] q) {
int ans = 0;
for (int i = q.length - 1; i >= 0; i--) {
if (q[i] - (i + 1) > 2) {
System.out.println("Too chaotic");
return;
}
for (int j = Math.max(0, q[i] - 2); j < i; j++)
if (q[j] > q[i]) ans++;
}
System.out.println(ans);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int a0 = 0; a0 < t; a0++){
int n = in.nextInt();
int[] q = new int[n];
for(int q_i = 0; q_i < n; q_i++){
q[q_i] = in.nextInt();
}
minimumBribes(q);
}
in.close();
}
}