#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int NMAX = 1e5;
int n,m;
int a[NMAX + 5];
int b[NMAX + 5];
bool usedL[NMAX + 5];
bool usedR[NMAX + 5];
priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int> > >,greater<pair<int,pair<int,int> > > > pq;
int main(){
cin >> n >> m;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
for(int i = 1;i <= m;i++){
cin >> b[i];
}
if(n > m){
for(int i = 1;i <= n || i <= m;i++){
swap(a[i],b[i]);
}
swap(n,m);
}
sort(a + 1,a + 1 + n);
sort(b + 1,b + 1 + m);
int ind = 0;
for(int i = 1;i <= n;i++){
while(ind < m && b[ind + 1] <= a[i]){
ind++;
}
if(ind >= 0){
pq.push({a[i] - b[ind],{i,ind}});
}
if(ind - 1 >= 0){
pq.push({a[i] - b[ind - 1],{i,ind - 1}});
}
if(ind + 1 <= m){
pq.push({b[ind + 1] - a[i],{i,ind + 1}});
}
if(ind + 2 <= m){
pq.push({b[ind + 2] - a[i],{i,ind + 2}});
}
}
long long ans = 0;
while(!pq.empty()){
int x = pq.top().second.first;
int y = pq.top().second.second;
int val = pq.top().first;
pq.pop();
if(!usedL[x] && !usedR[y]){
usedL[x] = true;
usedR[y] = true;
ans = max(ans,(long long)val);
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
8936 KB |
Output is correct |
2 |
Incorrect |
224 ms |
10772 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
214 ms |
12624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12624 KB |
Output is correct |
2 |
Incorrect |
10 ms |
12624 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12624 KB |
Output is correct |
2 |
Incorrect |
9 ms |
12624 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
12624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
12624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
166 ms |
12660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
189 ms |
12780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
160 ms |
14032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |