#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n,m;
int mini,maks;
long long 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);
}
long long lo = 0, hi = maks;
while (lo != hi) {
long long zas = 0;
long long pom = 0,ad = 0;
long long mid = (lo + hi) / 2;
for (long long i = 0;i < n;i++) {
for (long long 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 |
131 ms |
2428 KB |
Output is correct |
2 |
Correct |
165 ms |
2356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
163 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
504 KB |
Output is correct |
2 |
Correct |
10 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
424 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 |
11 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
504 KB |
Output is correct |
2 |
Correct |
10 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
2268 KB |
Output is correct |
2 |
Correct |
94 ms |
1808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
147 ms |
2356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
1984 KB |
Output is correct |
2 |
Incorrect |
137 ms |
2140 KB |
Output isn't correct |