#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;
while(l > gl && B[l - 1] >= B[r]){
l--; ch = 1;
}
while(r < gr && B[l] >= B[r + 1]){
r++; 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;
while(l < gl && B[l + 1] >= B[r]){
l++; ch = 1;
}
while(r > gr && B[l] >= B[r - 1]){
r--; 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |