-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMonkAndInversion.java
42 lines (34 loc) · 1.23 KB
/
MonkAndInversion.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
36
37
38
39
40
41
42
package Hackerearth;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class MonkAndInversion {
public static void main(String[] args) throws IOException {
StringBuilder op=new StringBuilder("");
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
int t= Integer.parseInt(bf.readLine());
while(t-->0){
int n =Integer.parseInt(bf.readLine());
int[][] matrix=new int[n][n];
for(int i=0;i<n;i++){
String[] mat=bf.readLine().split(" ");
for(int j=0;j<n;j++){
matrix[i][j]= Integer.parseInt(mat[j]);
}
}
int count=0;
for(int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
int temp=matrix[i][j];
for (int k=i;k<n;k++) {
for (int l=j;l<n;l++) {
if(temp>matrix[k][l]) count++;
}
}
}
}
op.append(count).append("\n");
}
System.out.println(op);
}
}