Submission #197774

#TimeUsernameProblemLanguageResultExecution timeMemory
197774MalomalomalomaloWatching (JOI13_watching)C++14
100 / 100
348 ms16248 KiB
#include <bits/stdc++.h> #define gmin(x,y) x=min(x,y) #define all(c) c.begin(), c.end() using namespace std; const int N = 2e3 + 5; int dp[N][N]; const int inf = 1e9; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n,p,q; cin >> n >> p >> q; gmin(p,n); gmin(q,n); vector<int> pos(n+1); for(int i = 1;i <= n; ++i){ cin >> pos[i]; } sort(all(pos)); int l = 1, r = 1e9, ans = inf; while(l <= r){ int m = l + (r-l)/2; for(int i = 0;i <= n; ++i){ for(int j = 0;j <= n; ++j){ dp[i][j] = inf; } } dp[0][0] = 0; for(int i = 0;i < n; ++i){ int nxts = (int)(upper_bound(all(pos), pos[i+1] + m - 1) - pos.begin()) - 1; int nxtl = (int)(upper_bound(all(pos), pos[i+1] + 2*m - 1) - pos.begin()) - 1; for(int j = 0;j <= n; ++j){ gmin(dp[nxts][j+1], dp[i][j]); gmin(dp[nxtl][j], dp[i][j] + 1); } } int mn = inf; for(int i = 0;i <= p; ++i){ gmin(mn, dp[n][i]); } if(mn <= q){ ans = m; r = m - 1; } else{ l = m + 1; } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...