Submission #521375

#TimeUsernameProblemLanguageResultExecution timeMemory
521375amunduzbaevWatching (JOI13_watching)C++14
0 / 100
415 ms16096 KiB
#include "bits/stdc++.h" using namespace std; #define ar array const int N = 2e3 + 5; int a[N], n, p, q; int dp[N][N], pw[N], p2w[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>p>>q; for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a + 1, a + n + 1); a[0] = -2e9; p = min(p, n), q = min(q, n); auto check = [&](int w){ memset(dp, 127, sizeof dp); memset(pw, -1, sizeof pw); memset(p2w, -1, sizeof p2w); for(int i=1;i<=n;i++){ for(int j=i-1;j>=0;j--){ if(a[i] - a[j] + 1 > w && pw[i] == -1) pw[i] = j; if(a[i] - a[j] + 1 > 2 * w && p2w[i] == -1) p2w[i] = j; } } for(int i=0;i<N;i++) dp[0][i] = 0; for(int i=1;i<=n;i++){ for(int j=0;j<=n;j++){ if(j > 0) dp[i][j] = min(dp[i][j], dp[pw[i]][j - 1]); dp[i][j] = min(dp[i][j], dp[p2w[i]][j] + 1); } } return (dp[n][p] <= q); }; int l = 1, r = 1e9; while(l < r){ int m = (l + r) >> 1; if(check(m)) r = m; else l = m + 1; } //~ cout<<check(l)<<" "; cout<<l<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...