이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool solve(int n, int k, ll t, vector<ll> x) {
int l = k, r = k, L=k, R = k;
for(int i=0; i<n; ++i) {
while(l > 0 && (R-l+1) * t - (x[R] - x[l-1]) / 2 >= 0LL) {
l--;
if((k-l) * t + x[l] / 2 > (k-L) * t + x[L] / 2) {
L = l;
}
}
while(r < n-1 && (r-L+1) * t - (x[r+1] - x[L]) / 2 >= 0LL) {
r++;
if((r-k) * t - x[r] / 2 > (R-k) * t - x[R] / 2) {
R = r;
}
}
}
return l==0 && r==n-1;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k;
ll t;
cin>>n>>k>>t;
k--;
t *= 2LL;
vector<ll> x(n);
for(int i=0; i<n; ++i) {
cin>>x[i];
x[i] *= 2LL;
}
ll lo = 0, hi = 1e10 / t + 1;
while(lo<=hi) {
ll mid = (lo+hi)/2LL;
if(solve(n, k, t*mid, x)) {
hi = mid-1;
}
else {
lo = mid+1;
}
}
cout<<hi+1<<'\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... |