Submission #1114760

#TimeUsernameProblemLanguageResultExecution timeMemory
1114760NewtonabcWatching (JOI13_watching)C++14
100 / 100
708 ms16208 KiB
#include<bits/stdc++.h> using namespace std; const int N=2e3+10; int dp[N][N],arr[N]; int main(){ int n,p,q; cin>>n >>p >>q; for(int i=1;i<=n;i++) cin>>arr[i]; arr[n+1]=INT_MAX; sort(arr+1,arr+n+1); int l=0,r=1e9; p=min(p,n),q=min(q,n); while(l<r){ int w=(l+r)/2; for(int i=0;i<=p;i++) for(int j=0;j<=q;j++) dp[i][j]=0; for(int i=0;i<=p;i++){ for(int j=0;j<=q;j++){ if(i) dp[i][j]=max(dp[i][j],dp[i-1][j]); if(j) dp[i][j]=max(dp[i][j],dp[i][j-1]); if(dp[i][j]==n) continue; if(i) dp[i][j]=max(dp[i][j],dp[i-1][j]+(int)(upper_bound(arr+dp[i-1][j]+1,arr+n+2,w+arr[dp[i-1][j]+1]-1)-(arr+dp[i-1][j]+1))); if(j) dp[i][j]=max(dp[i][j],dp[i][j-1]+(int)(upper_bound(arr+dp[i][j-1]+1,arr+n+2,2*w+arr[dp[i][j-1]+1]-1)-(arr+dp[i][j-1]+1))); } } if(dp[p][q]==n) r=w; else l=w+1; /*cout<<w <<"\n"; for(int i=0;i<=p;i++){ for(int j=0;j<=q;j++){ cout<<dp[i][j] <<" "; } cout<<"\n"; }*/ } cout<<l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...