#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 plusic) {//cout << "funkcija\n";
for (int i = 0;i < n;i++) {
// cout << i << " " << i + plus <<endl << endl;
if (abs(niz1[i] - niz2[i + plusic]) > 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 ind = 0;
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);
ind = i;
if (b == 0) {
zas = 1;
}
else {
}
// cout << mid << " " << i << " bool: " << b << endl;
break;
}
}
if (zas == 1) {
lo = mid + 1;
}
else {
hi = mid;
}
}
while (f(lo-1,ind)) {
lo--;
}
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 |
130 ms |
2680 KB |
Output is correct |
2 |
Correct |
160 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
2928 KB |
Output is correct |
2 |
Correct |
159 ms |
3040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Incorrect |
11 ms |
636 KB |
Output isn't 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 |
7 ms |
376 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 |
8 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
133 ms |
2476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
2736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
128 ms |
2508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |