#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define endl "\n"
#define Sara ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const long long mod=998244353;
const double PI=acos(-1);
int main()
{
//freopen("input.in","r",stdin);
Sara
// 2nd st
int n,m;
cin>>n>>m;
vector<ll>a(n),b(m);
for(int i=0; i<n; i++)
cin>>a[i];
for(int i=0; i<m; i++)
cin>>b[i];
sort(a.begin(),a.end());
sort(b.begin(),b.end());
ll mx=0;
if(n<m)
{
ll mn=1e9;
for(int i=0; i<=(m-1)-(n-1); i++)
{
mx=0;
int k=0;
for(int j=i; j<i+n; j++)
{
mx=max(mx,abs(b[j]-a[k]));
// cout<<b[j]<<' '<<a[k]<<endl;
k++;
}
//cout<<mx<<endl;
mn=min(mn,mx);
}
cout<<mn<<endl;
return 0;
}
ll mn=1e9;
for(int i=0; i<=(n-1)-(m-1); i++)
{
mx=0;
int k=0;
for(int j=i; j<i+m; j++)
{
mx=max(mx,abs(a[j]-b[k]));
k++;
}
mn=min(mn,mx);
}
cout<<mn<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1868 KB |
Output is correct |
2 |
Correct |
41 ms |
1888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
1868 KB |
Output is correct |
2 |
Correct |
42 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
1484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1002 ms |
1696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1084 ms |
1484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |