forked from sourav959/Google-Kick-Start-Round-G-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWalktober.java
33 lines (32 loc) · 977 Bytes
/
Walktober.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
import java.util.*;
class Solution{
public static long solve(int[][] inpArr,int N,int M,int P){
long ans=0;
for(int j=0;j<N;j++){
int maximum=Integer.MIN_VALUE;
for(int i=0;i<M;i++){
if(inpArr[i][j]>maximum)
maximum=inpArr[i][j];
}
ans+=(maximum-inpArr[P-1][j]);
}
return ans;
}
public static void main(String[] agrs){
Scanner sc=new Scanner(System.in);
int testCase=sc.nextInt();
for(int test=1;test<=testCase;test++){
int M=sc.nextInt();
int N=sc.nextInt();
int P=sc.nextInt();
int[][] inpArr=new int[M][N];
for(int i=0;i<M;i++){
for(int j=0;j<N;j++){
inpArr[i][j]=sc.nextInt();
}
}
long ans=solve(inpArr,N,M,P);
System.out.println("Case #"+test+": "+ans);
}
}
}