#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n,m;
int niz1[N],niz2[N];
int maks;
int main () {
cin >> n >> m;
for (int i = 0;i < n;i++) {
cin >> niz1[i];
if (niz1[i] > maks) {
maks = niz1[i];
}
}
for (int i = 0;i < m;i++) {
cin >> niz2[i];
if (niz2[i] > maks) {
maks = niz2[i];
}
}
sort(niz1,niz1 + n);
sort(niz2,niz2 + m);
if (n > m) {
for (int i = 0;i < n;i++) {
swap(niz1[i],niz2[i]);
}
swap(n,m);
}
/*
for (int i = 0;i < n;i++) {
cout << niz1[i] << " ";
}cout << endl;
for (int i = 0;i < m;i++) {
cout << niz2[i] << " ";
}cout << endl;
*/
// prvi je manji prvi je manji prvi je manji prvi je manji
int lo = 0, hi = maks;
while (lo != hi) {
int zas = 0;
int mid = (lo + hi) / 2;
// cout << mid << endl;
for (int i = 0;i < n;i++) {
int plus = 0;
while(abs(niz1[i] - niz2[i + plus]) > mid) {
plus++;
if (i + plus >= m) {
zas = 1;
break;
}
}
if (zas == 1) {
break;
}
for (int ind = i;ind < n - plus;ind++) {//cout << ind << " ind|plus " << plus <<endl;
if (abs(niz1[ind] - niz2[ind + plus]) > mid) {//cout << "umre na " << ind << " zas " << zas << endl;
zas = 1;
break;
}
}
}
if (zas == 0) {
hi = mid;
}
else {
lo = mid + 1;
}
}
cout << lo <<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
2680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
2808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
376 KB |
Output is correct |
2 |
Correct |
191 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
2408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
2552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
2380 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |