#include<bits/stdc++.h>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<long long> l(n);
vector<long long> r(m);
for(int i = 0; i < n; i++){
cin >> l[i];
}
for(int i = 0; i < m; i++){
cin >> r[i];
}
sort(l.begin(), l.end());
sort(r.begin(), r.end());
if(n == m){
long long ans = INT_MIN;
for(int i = 0; i < n; i++){
ans = max(ans, abs(l[i] - r[i]));
}
cout << ans << "\n";
}
else{
if(n > m){
swap(n, m);
swap(l, r);
}
bool isPaired[m];
long long ans = INT_MIN;
memset(isPaired, false, sizeof(isPaired));
for(int i = 0; i < n; i++){
long long minCost = INT_MAX;
long long cur = -1;
for(int j = 0; j < m; j++){
if(isPaired[j]){
continue;
}
if(minCost > abs(l[i] - r[j])){
minCost = abs(l[i] - r[j]);
cur = j;
}
}
ans = max(ans, abs(l[i] - r[i]));
isPaired[cur] = true;
}
cout << ans << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
1876 KB |
Output is correct |
2 |
Correct |
95 ms |
1856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
1876 KB |
Output is correct |
2 |
Correct |
78 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
26 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
1572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
1688 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
1536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |