Problem Link:
Practice
Contest
Difficulty:
CakeWalk
Problem:
Find the minimum amount to purchase all types of stones.
Explanation:
The input is N*N matrix. We can consider it as N different arrays. We just need to add the minimum of every array. This is our required answer. We can do it by inputting one array at a time and finding the minimum of the array and then input the next array.
Solution:
Author’s Solution can be found here.
for t in range(input()):
n,m=map(int,raw_input().split())
a=0
for i in range(n):
c=map(int,list(raw_input().split()))
c.sort()
a=a+c[0]
print a
private static int calculate() {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int N =sc.nextInt();
int M = sc.nextInt();
int price[][] = new int[N][M];
int total = 0 , min=0 , x = -1;
for(int i =0 ; i<N ; i++)
{
for(int j=0 ; j<M ; j++)
{
price[i][j]=sc.nextInt();
if(x!=i)
{
min=price[i][j];
x=i;
}
else
{
if(price[i][j] < min)
min=price[i][j];
}
}total+=min;
}
return total ;
}
}