#include <bits/stdc++.h>
using namespace std;
void solve(vector<int>& ar, int D){
if((int)ar.size() == 1){
cout << 0 << ' ';
return;
}
assert(is_sorted(ar.begin(), ar.end()));
int N = (int)ar.size();
vector<long long> pref(N), suff(N);
for(int i = 1; i < N; ++i){
pref[i] = pref[i - 1] + max(D - (ar[i] - ar[i - 1]), 0);
}
for(int i = N - 2; i >= 0; --i){
suff[i] = suff[i + 1] + max(D - (ar[i] - ar[i + 1]), 0);
}
long long ans = min(suff[0], pref[N - 1]);
for(int i = 0; i + 1 < N; ++i){
ans = min(ans, max(pref[i], suff[i + 1]) * 2 + max(D - ar[i + 1] + ar[i], 0));
}
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, D;
cin >> N >> M >> D;
vector<int> ar;
for(int i = 1; i <= N; ++i){
int x; cin >> x;
ar.push_back(x);
}
sort(ar.begin(), ar.end());
for(int i = 1; i <= M; ++i){
int x; cin >> x;
ar.insert(lower_bound(ar.begin(), ar.end(), x), x);
solve(ar, D);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1530 ms |
1396 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1530 ms |
1396 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |