#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n,m;
int mini,maks;
int niz1[N],niz2[N];
int main () {
cin >> n >> m;
for (long long i = 0;i < n;i++) {
cin >> niz1[i];
if (niz1[i] > maks) {
maks = niz1[i];
}
if (niz1[i] < mini) {
mini = niz1[i];
}
}
for (long long i = 0;i < m;i++) {
cin >> niz2[i];
if (niz2[i] > maks) {
maks = niz2[i];
}
if (niz2[i] < mini) {
mini = niz2[i];
}
}
sort(niz1,niz1 + n);
sort(niz2,niz2 + m);
// prvi je manji prvi je manji prvi je manji
if (n > m) {
for (long long i = 0;i < n;i++) {
swap(niz1[i],niz2[i]);
}
swap(n,m);
}
int lo = 0, hi = maks;
while (lo != hi) {
int zas = 0;
int pom = 0,ad = 0;
int mid = (lo + hi) / 2;
for (int i = 0;i < n;i++) {
for (int j = i + ad;j < m;j++) {
if (abs(niz1[i] - niz2[j]) <= mid) {
//uspio sam uparit
break;
}
if (j == m - 1) {//nisam ga naso uopce
zas = 1;
}
pom++;
}
ad = pom;
}
if (zas == 1) {
lo = mid + 1;
}
else {
hi = mid;
}
}
cout << lo << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
2808 KB |
Output is correct |
2 |
Correct |
160 ms |
2916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
160 ms |
3056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
424 KB |
Output is correct |
2 |
Correct |
10 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
2396 KB |
Output is correct |
2 |
Correct |
93 ms |
1784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
145 ms |
2632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
2412 KB |
Output is correct |
2 |
Incorrect |
136 ms |
2516 KB |
Output isn't correct |