Submission #132810

#TimeUsernameProblemLanguageResultExecution timeMemory
132810miguelWatching (JOI13_watching)C++14
100 / 100
425 ms31864 KiB
#include<bits/stdc++.h> //#include<gondola.h> using namespace std; #define rc(x) return cout<<x<<endl,0 #define pb push_back #define dbg(x) cout << #x << '=' << x << '\n'; #define ll long long #define int ll #define sz size() #define x first #define y second #define pi pair <int, int> #define pii pair <int, pi> #define vi vector <int> const ll mod = 998244353; int n, p, q, dp[2005][2005]; int w[2005]; bool check(int d){ for(int i=0; i<=n; i++){ for(int j=0; j<=p; j++) dp[i][j]=1e18; } dp[0][0]=0; for(int j=1; j<=p; j++) dp[0][j]=0; for(int i=0; i<n; i++){ int x=(upper_bound(w+1, w+n+1, w[i+1]+d-1)-w)-1; int y=(upper_bound(w+1, w+n+1, w[i+1]+2*d-1)-w)-1; for(int j=0; j<=p; j++){ if(j<p) dp[x][j+1]=min(dp[x][j+1], dp[i][j]); dp[y][j]=min(dp[y][j], dp[i][j]+1); } } /*if(d<=8)cout<<d<<"\n"; if(d<=8){ for(int i=0; i<=n; i++){ for(int j=0; j<=p; j++){ cout<<dp[i][j]<<" "; }cout<<endl; } cout<<endl; }*/ return (dp[n][p]<=q); } int32_t main(){ ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cin>>n>>p>>q; p=min(p, n); for(int i=1; i<=n; i++){ cin>>w[i]; } int l=0, r=1e9+1; sort(w+1, w+n+1); //w.pb(1000000001); while(r-l>1){ int mid=(l+r)>>1; if(check(mid)) r=mid; else l=mid; } cout<<r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...