#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;
const int NS = (int)1e5 + 4;
int n, k, t;
int a[NS];
int mn[1004][1004], mx[1004][1004];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k >> t;
--k;
for(int i = 0; i < n; ++i){
cin >> a[i];
}
int low = 0, high = (int)1e9, mid;
while(low < high){
mid = low + high >> 1;
mn[k][k] = a[k] - t * mid;
mx[k][k] = a[k] + t * mid;
for(int i = n - 1; i >= 0; --i){
for(int j = i + 1; j < n; ++j){
mn[i][j] = (int)1e18;
mx[i][j] = -(int)1e18;
int l = mn[i + 1][j], r = mx[i + 1][j];
r = min(r, a[i] + (j - i) * t * mid);
l = max(l, a[i] - (j - i) * t * mid);
if(l <= r){
mx[i][j] = max(mx[i][j], r + t * mid);
mn[i][j] = min(mn[i][j], l - t * mid);
}
l = mn[i][j - 1], r = mx[i][j - 1];
r = min(r, a[j] + (j - i) * t * mid);
l = max(l, a[j] - (j - i) * t * mid);
if(l <= r){
mx[i][j] = max(mx[i][j], r + t * mid);
mn[i][j] = min(mn[i][j], l - t * mid);
}
}
}
if(mn[0][n - 1] != (int)1e18){
high = mid;
}
else{
low = mid + 1;
}
}
cout << low << '\n';
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:24:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | mid = low + high >> 1;
| ~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |