This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
const int inf = 1e9 + 5;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, k, t; cin>>n>>k>>t;
vector<int> a(n), d(n);
for(int i=0;i<n;i++) cin>>a[i], a[i] *= 2;
for(int i=1;i<n;i++){
d[i] = a[i] - a[i-1];
}
k--;
auto check = [&](int s){
vector<vector<int>> dp(n, vector<int>(n, -1));
dp[k][k] = t * s;
for(int len=0;len<n;len++){
for(int i=0;i+len<n;i++){
int j=i+len;
if(j+1<n){
int D = d[j+1] / 2;
if(dp[i][j] >= D){
dp[i][j+1] = max(dp[i][j+1], dp[i][j] - D + t * s);
}
} if(i){
int D = d[i] / 2;
if(dp[i][j] >= D){
dp[i-1][j] = max(dp[i-1][j], dp[i][j] - D + t * s);
}
}
}
}
return (~dp[0][n-1]);
};
int l = 0, r = 2 * inf;
while(l < r){
int m = (l + r) >> 1;
if(check(m)) r = m;
else l = m + 1;
}
cout<<(l+1) / 2<<"\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... |