#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, K, T, A[100005], B[100005];
bool f(ll v){
for(ll i = 1; i <= N; i++){
B[i] = A[i] - 2 * v * T * i;
}
ll gl = K, gr = K;
for(ll i = 1; i <= N; i++){
if(i <= K && B[gl] <= B[i]) gl = i;
if(i >= K && B[gr] >= B[i]) gr = i;
}
ll l = K, r = K;
while(1){
ll ch = 0, nl = l, nr = r;
while(nl > gl && B[nl - 1] >= B[r]) nl--;
if(B[nl] >= B[l] && nl < l){
l = nl, ch = 1;
}
while(nr < gr && B[nr + 1] <= B[l]) nr++;
if(B[nr] <= B[r] && nr > r){
r = nr, ch = 1;
}
if(ch == 0) break;
}
if(l != gl || r != gr) return 0;
l = 1, r = N;
if(B[l] < B[r]) return 0;
while(1){
ll ch = 0, nl = l, nr = r;
while(nl < gl && B[nl + 1] >= B[r]) nl++;
if(B[nl] >= B[l] && nl > l){
l = nl, ch = 1;
}
while(nr > gr && B[nr - 1] <= B[l]) nr--;
if(B[nr] <= B[r] && nr < r){
r = nr, ch = 1;
}
if(ch == 0) break;
}
return (l == gl && r == gr);
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> N >> K >> T;
for(ll i = 1; i <= N; i++){
cin >> A[i];
}
if(A[N] == 0){
cout << 0; return 0;
}
ll L = 1, R = 1e9;
while(L <= R){
ll m = (L + R) / 2;
if(f(m)) R = m - 1;
else L = m + 1;
}
cout << L;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |