Submission #867245

#TimeUsernameProblemLanguageResultExecution timeMemory
867245ElioritaWatching (JOI13_watching)C++14
100 / 100
287 ms31836 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define x first #define y second #define getbit(u,i) ((u>>i)&1) #define all(x) x.begin(),x.end() #define N 200001 using namespace std; typedef pair<int,int> ii; typedef pair<double,double> dd; int n,a,b,A[N],dp[2001][2001],ans,l=1,r=1e9+8; bool check(int x) { int mn=LLONG_MAX; memset(dp,0x3f,sizeof(dp)); dp[0][0]=0; for(int i=1;i<=n;i++) { int l=1,r=1; while(l<i&&A[i]>=x+A[l]) l++; for(int j=0;j<=b;j++) dp[i][j]=dp[l-1][j]+1; while(r<i&&A[i]>=2*x+A[r]) r++; for(int j=0;j<=b;j++) dp[i][j+1]=min(dp[i][j+1],dp[r-1][j]); } for(int i=0;i<=b;i++) mn=min(mn,dp[n][i]); return mn<=a; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>a>>b; if(n<=a+b) {cout<<1; return 0;} for(int i=1;i<=n;i++) cin>>A[i]; sort(A+1,A+n+1); while(l<=r) { int m=(l+r)/2; if(check(m)) { ans=m; r=m-1; } else l=m+1; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...