이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
ll d, a[500005];
ll solve(int n){
sort(a, a + n);
ll lastpos = a[0], tim = 0;
for(int i = 1; i < n; i++){
if(a[i] - lastpos >= d) lastpos = max(lastpos + d, a[i] - tim);
else if(a[i] + tim - lastpos >= d) lastpos += d;
else{
ll need = d - (a[i] - lastpos) - tim, x = a[i] + tim;
need /= 2;
tim += need;
lastpos = x + need;
}
}
return tim;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m; cin >> n >> m >> d;
d *= 2;
for(int i = 0; i < n; i++){
cin >> a[i];
a[i] *= 2;
}
sort(a, a + n);
ll lastpos, tim;
for(int i = 0; i < m; i++){
cin >> a[i + n];
a[i + n] *= 2;
ll ans;
if(m > 10){
if(i == 0) lastpos = a[0], tim = 0;
else{
if(a[i] - lastpos >= d) lastpos = max(lastpos + d, a[i] - tim);
else if(a[i] + tim - lastpos >= d) lastpos += d;
else{
ll need = d - (a[i] - lastpos) - tim, x = a[i] + tim;
need /= 2;
tim += need;
lastpos = x + need;
}
}
ans = tim;
}
else ans = solve(i + n + 1);
cout << ans / 2 << (ans & 1 ? ".5 " : " ");
}
}
# | 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... |