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;
void solve(vector<long long>& ar, int D){
if((int)ar.size() == 1){
cout << 0 << ' ';
return;
}
assert(is_sorted(ar.begin(), ar.end()));
int N = (int)ar.size();
long long l = 0, r = 1e18, ans = 0;
while(l <= r){
long long mid = l + r >> 1;
bool ok = true;
long long last = ar[0] - mid;
for(int i = 1; i < N; ++i){
if(last + D < ar[i] - mid){
last = ar[i] - mid;
} else if(last + D > ar[i] + mid){
ok = false;
break;
} else{
last += D;
}
}
if(ok) ans = mid, r = mid - 1;
else l = mid + 1;
}
if(ans & 1) cout << (ans >> 1) << ".5 ";
else cout << (ans >> 1) << ' ';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
#endif // LOCAL
int N, M;
long long D;
cin >> N >> M >> D;
D <<= 1;
vector<long long> ar;
for(int i = 1; i <= N; ++i){
long long x; cin >> x;
ar.push_back(x << 1);
}
sort(ar.begin(), ar.end());
for(int i = 1; i <= M; ++i){
long long x; cin >> x;
x <<= 1;
ar.insert(lower_bound(ar.begin(), ar.end(), x), x);
solve(ar, D);
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void solve(std::vector<long long int>&, int)':
Main.cpp:16:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
16 | long long mid = l + r >> 1;
| ~~^~~
# | 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... |