#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
vector<int> a;
vector<int> b;
int memo[5009][5009];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
a.resize(n+1);
b.resize(m+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= m; i++){
cin >> b[i];
}
sort(a.begin()+1, a.end());
sort(b.begin()+1, b.end());
if(n <= 5000 && m <= 5000){
vector<int> t(a);
if(n > m){
swap(a,b);
}
for(int l = 1; l <= min(n,m); l++){
for(int r = 1; r <= max(n,m); r++){
if(r >= l) memo[l][r] = min(memo[l][r-1], max(memo[l-1][r-1], abs(a[l]-b[r])));
else memo[l][r] = INF/2;
}
}
cout << memo[min(n,m)][max(n,m)] << endl;
}
else{
int maxi = -INF;
for(int i = 0; i < m; i++){
maxi = max(maxi, abs(a[i]-b[i]));
}
cout << maxi << endl;
}
// }
}
/*
5 5
7 6 1 2 10
9 11 6 3 12
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
1972 KB |
Output is correct |
2 |
Correct |
45 ms |
2004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
1920 KB |
Output is correct |
2 |
Correct |
49 ms |
1968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
59388 KB |
Output is correct |
2 |
Correct |
214 ms |
196344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4352 KB |
Output is correct |
2 |
Correct |
199 ms |
196368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
137656 KB |
Output is correct |
2 |
Correct |
191 ms |
196324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
137592 KB |
Output is correct |
2 |
Correct |
187 ms |
196320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
176888 KB |
Output is correct |
2 |
Correct |
187 ms |
196344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
41 ms |
3088 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
46 ms |
3320 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
43 ms |
2940 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |