#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n,m;
int mini,maks;
int niz1[N],niz2[N];
bool f(int val, int plus) {//cout << "funkcija\n";
for (int i = 0;i < n;i++) {
// cout << i << " " << i + plus <<endl << endl;
if (abs(niz1[i] - niz2[i + plus]) > val) {
return false;
}
}
return true;
}
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);
if (n > m) {
for (long long 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 < niz2[i];i++) {
cout << niz2[i] << " ";
}cout << endl;
*/ int lo = 0, hi = maks;
while (lo != hi) {
int mid = (lo + hi) / 2;
int zas = 0;
for (int i = 0;i <= m - n;i++) {
if (abs(niz1[0] - niz2[i]) < mid) {
bool b = f(mid,i);
if (b == 0) {
zas = 1;
}
// cout << mid << " " << i << " bool: " << b << endl;
break;
}
}
if (zas == 1) {
lo = mid + 1;
}
else {
hi = mid;
}
}
for (int i = 0;i <= m - n;i++) {
if (f(lo,i) == 1) {
cout << lo << endl;
return 0;
}
}
cout << lo + 1 << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
2680 KB |
Output is correct |
2 |
Correct |
161 ms |
2932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
2932 KB |
Output is correct |
2 |
Correct |
160 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Incorrect |
10 ms |
504 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
7 ms |
372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
134 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
144 ms |
2556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
126 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |