This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int n,m;scanf("%d %d",&n,&m);
int a[n][m];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&a[i][j]);
for(int i=0;i<n;i++)
sort(a[i],a[i]+m);
int ans=987654321;
int p[n];
for(int i=0;i<n;i++)p[i]=0;
int cnt=0;
while(cnt!=n*(m-1)){
int min=0,max=0;
for(int i=0;i<n;i++){
if(a[i][p[i]]<a[min][p[min]])min=i;
if(a[i][p[i]]>a[max][p[max]])max=i;
}
//printf("%d %d\n",min,max);
if(ans>a[max][p[max]]-a[min][p[min]])ans=a[max][p[max]]-a[min][p[min]];
if(p[min]==m-1)break;
p[min]++;
cnt++;
}
printf("%d",ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |