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 <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <cstring>
using namespace std;
#define in cin
#define out cout
#define all(v) v.begin(), v.end()
#define X first
#define Y second
int CNT[1010];
int main()
{
int n, m; in >> n >> m;
vector< pair<int, int> > v;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
int x; in >> x;
v.push_back(make_pair(x, i));
}
}
sort(all(v));
int q = 0;
int K = 0;
int res = 101010101;
for(int p=0; p<n*m; p++)
{
if(CNT[ v[p].Y ] == 0) K++;
CNT[ v[p].Y ]++;
while(K == n)
{
if(v[p].X - v[q].X < res) res = v[p].X - v[q].X;
CNT[ v[q].Y ]--;
if(CNT[ v[q].Y ] == 0) K--;
q++;
}
}
int p = n*m-1;
while(K == n)
{
if(v[p].X - v[q].X < res) res = v[p].X - v[q].X;
CNT[ v[q].Y ]--;
if(CNT[ v[q].Y ] == 0) K--;
q++;
}
out << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |