#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii ;
typedef pair<ll, ll> pll ;
typedef vector<pii> vii ;
typedef vector<int> veci ;
typedef vector<pll> vll ;
typedef vector<ll> vecll;
// find_by_order order_of_key
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define Mp make_pair
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define lb lower_bound
#define ub upper_bound
#define for1(n) for(int i=1;i<=n;i++)
#define for0(n) for(int i=0;i<n;i++)
#define forn(n) for(int i=n;i>0;i--)
#define pq priority_queue <pii, vector<pii>, greater<pii>>
const ll mod = 2e9 ;// 998244353 ;// 1e9+9;
ll inf=1e18;
const int N=5e3+100,L=21,bs=701,NN=1e6;
int B[N],C[N],D[N],E[N],n,m,q;
vector<int>g[N];
bitset<N> is[N];
ll A[N],t,k;
// bool check2(ll x,ll t){
// ll e=max(abs(A[k]-x),abs(A[k-1]-x));
// if(e>t)return 0;
// ll kk=k-2,tmp=0;
// while(kk>0){
// if(x-(A[kk]+e)<=t*2 && kk>0){
// kk--;
// tmp++;
// }
// if(tmp==0)return 0;
// tmp--;
// e+=t;
// x-=t;
// x=max(x,0ll);
// }
// return 1;
// }
// bool check3(ll x,ll t){
// ll e=max(abs(A[k]-x),abs(A[k-1]-x));
// if(e>t)return 0;
// if(x<=A[k]){
// x+=t-e;
// e=t;
// }
// ll kk=k+1,tmp=0;
// while(kk<=n){
// if((A[kk]-e)-x<=0 && kk<=n){
// kk++;
// tmp++;
// }
// if(tmp==0)return 0;
// tmp--;
// e+=t;
// x+=t;
// x=min(x,mod);
// }
// return 1;
// }
// bool check4(ll x,ll t){
// ll e=max(abs(A[k]-x),abs(A[k-1]-x));
// if(e>t)return 0;
// e+=t;
// x+=t;
// ll kk=k+1,tmp=0;
// while(kk<=n){
// if((A[kk]-e)-x<=0 && kk<=n){
// kk++;
// tmp++;
// }
// if(tmp==0)return 0;
// tmp--;
// e+=t;
// x+=t;
// x=min(x,mod);
// }
// return 1;
// }
// bool check5(ll x,ll t){
// ll e=max(abs(A[k]-x),abs(A[k-1]-x));
// if(e>t)return 0;
// x-=t-e;
// ll kk=k-2,tmp=0;
// while(kk>0){
// if(x-(A[kk]+e)<=0 && kk>0){
// kk--;
// tmp++;
// }
// if(tmp==0)return 0;
// tmp--;
// e+=t;
// x-=t;
// x=max(x,0ll);
// }
// return 1;
// }
// bool checkk(ll t){
// if(k==1)return 0;
// ll l=A[k]-t,r=A[k-1]+t+1;
// while(r-l>1){
// ll mid=(l+r)>>1;
// if(check2(mid,t))l=mid;
// else r=mid;
// }
// if(check3(l,t) && check2(l,t))return 1;
// l=A[k]-t-1,r=A[k-1]+t;
// while(r-l>1){
// ll mid=(l+r)>>1;
// if(check4(mid,t)==0)l=mid;
// else r=mid;
// }l++;
// if(check4(l,t) && check5(l,t))return 1;
// return 0;
// }
// bool check(ll t){
// if(checkk(t))return 1;
// for1(n)A[i]=A[n]-A[i];
// reverse(A+1,A+n+1);
// k=n+1-k;
// return(checkk(t));
// }
bool check(ll t){
for1(n)is[i]=0;
is[k][k]=1;
for(int d=1;d<n;d++){
for(int l=1;l<=n-d;l++){
int r=l+d;
if(is[l+1][r] && (r-l)*t*2-(A[r]-A[l])>=0)is[l][r]=1;
if(is[l][r-1] && (r-l)*t*2-(A[r]-A[l])>=0)is[l][r]=1;
}
}
return is[1][n];
}
int main(){
// fast_io
cin>>n>>k>>t;t*=2;
for1(n){
cin>>A[i];A[i]*=2;
}
ll l=0,r=mod*2/t+1;
while(r-l!=1){
ll mid=(l+r)>>1;
if(check(t*mid)==0)l=mid;
else r=mid;
}
cout<<l+1<<endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |