This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pi;
typedef long long int lint;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int n, m, par;
vector<int> a, b;
int main ()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
if(n >= m) {
for(int i = 0; i < n; ++i) {
int x; cin >> x;
b.pb(x);
}
for(int i = 0; i < m; ++i) {
int x; cin >> x;
a.pb(x);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
} else {
for(int i = 0; i < n; ++i) {
int x; cin >> x;
a.pb(x);
}
for(int i = 0; i < m; ++i) {
int x; cin >> x;
b.pb(x);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
}
if(n == m) {
int ans = 0;
for(int i = 0; i < n; ++i)
ans = max(ans, abs(a[i] - b[i]));
return cout << ans, 0;
}
int hi = 2 * max(abs(a[0] - b[b.size() - 1]), abs(b[0] - a[a.size() - 1]));
int lo = 0;
int mid = lo + (hi - lo) / 2;
int ans = inf;
while(lo <= hi) {
mid = lo + (hi - lo) / 2;
int cur = 0;
for(int i = 0; i < b.size(); ++i) {
if(abs(a[cur] - b[i]) <= mid)
++cur;
if(cur == a.size()) {
hi = mid - 1;
ans = min(ans, mid);
break;
}
}
// cout << "cur " << cur << " ans " << ans << endl;
if(!(cur == a.size()))
lo = mid + 1;
// cout << hi << " " << lo << endl;
}
int cur = 0;
mid = lo + (hi - lo) / 2;
for(int i = 0; i < b.size(); ++i) {
if(abs(a[cur] - b[i]) <= mid)
++cur;
}
if(cur == a.size())
ans = min(ans, mid);
cout << ans;
return 0;
}
Compilation message (stderr)
cipele.cpp: In function 'int main()':
cipele.cpp:62:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < b.size(); ++i) {
~~^~~~~~~~~~
cipele.cpp:65:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(cur == a.size()) {
~~~~^~~~~~~~~~~
cipele.cpp:72:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(!(cur == a.size()))
~~~~^~~~~~~~~~~
cipele.cpp:79:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < b.size(); ++i) {
~~^~~~~~~~~~
cipele.cpp:83:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(cur == a.size())
~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |