#include <bits/stdc++.h>
using namespace std;
long long solve(vector<int> coords, int D) {
sort(coords.begin(), coords.end());
long long x = coords[0];
long long cost = 0;
for(int i = 1; i < coords.size(); i++) {
long long a = coords[i];
//cout << "\t" << x << " " << cost << " " << a << "\n";
if(a + cost - x >= D) {
// move new as much left as possible without increasing cost
x = max(x + D, a - cost);
}
else {
// moving new right, increasing cost
long long costinc = D - (a + cost - x);
//cout << "\t" << costinc << " ";
cost += costinc;
x = a + cost;
//cout << "\n";
}
}
return cost;
}
int main() {
int N, M, D;
cin >> N >> M >> D;
vector<int> coordinates;
for(int i = 0; i < N; i++) {
int a;
cin >> a;
coordinates.push_back(2 * a);
}
for(int i = 0; i < M; i++) {
int a;
cin >> a;
coordinates.push_back(2 * a);
long long b = solve(coordinates, 2 * D);
cout << b / 4;
switch(b & 0x3) {
case 0:
break;
case 1:
cout << ".25";
break;
case 2:
cout << ".5";
break;
case 3:
cout << ".75";
break;
}
cout << " ";
}
return 0;
}
# | 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... |