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;
typedef long long ll;
ll dp(int n, vector<int> &x, int d) {
ll final = 0; // times 2
ll change = 2*d; // times 2
for (int i = 1; i < n; i++) {
int pos = x[i]-x[i-1];
change -= 2*pos;
if (change >= final) {
/*
(change-npos)+final = npos => npos = (change+final)/2;
*/
assert((change&1) == (final&1));
ll npos = (change+final)/2;
assert(npos <= change);
final += change-npos;
change = npos;
}
else if (-change >= final) {
ll npos = -final;
assert(npos >= change);
change = npos;
}
change += 2*d;
}
return final;
}
void print(ll a) {
cout << a/2;
if (a & 1) cout << ".5";
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, m, d;
cin >> n >> m >> d;
vector<int> elems;
for (int i = 0; i < n; i++) {
int x; cin >> x;
elems.push_back(x);
}
for (int j = 0; j < m; j++) {
int x; cin >> x;
elems.push_back(x);
sort(elems.begin(), elems.end()); // appreciate my laziness
if (j > 0) cout << ' ';
print(dp(n+j+1, elems, d));
}
cout << '\n';
}
# | 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... |