View Code of Problem 17

#include<iostream>
using namespace std;

int main(){
	int m,n;
	int t;
	int max;
	cin>>t;
	while(t--){
		cin>>n;
		cin>>m;
		int a[n][m];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				cin>>a[i][j];
			}
		}
		
		int x,y=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(a[x][y]>a[i][j]){
					x=i;
					y=j;
				}
			}
		}
		int u,v=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(a[u][v]<a[i][j]){
					u=i;
					v=j;
				}
			}
		}
		
		max=a[u][v]-a[x][y];
		cout<<max;
		
		
		
	}
  return 0;
} 

Double click to view unformatted code.


Back to problem 17