Submission #30872

#TimeUsernameProblemLanguageResultExecution timeMemory
30872NavickWatching (JOI13_watching)C++14
100 / 100
263 ms17968 KiB
#include <bits/stdc++.h> #define F first #define S second #define pii pair<int, int> #define pb push_back using namespace std; typedef long long ll; typedef long double ld; const int N = 2010, INF = 1e9 + 10; int dp[N][N], n, p, q; int a[N]; bool check(int w){ for(int j=0; j<=p; j++) dp[0][j] = 0; int ptr = -1, ptr2 = -1; for(int i=1; i<=n; i++){ while(a[i - 1] - a[ptr + 1] >= w)ptr++; while(a[i - 1] - a[ptr2 + 1] >= 2*w)ptr2++; for(int j=0; j<=p; j++){ dp[i][j] = INF; if(j > 0) dp[i][j] = dp[ptr + 1][j - 1]; if(q > 0){ dp[i][j] = min(dp[i][j], dp[ptr2 + 1][j] + 1); } } } if(dp[n][p] <= q)return true; return false; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> p >> q; p = min(p, n); q = min(q, n); for(int i=0; i<n; i++) cin >> a[i]; sort(a, a + n); n = unique(a,a + n) - a; int lo = 0, hi = INF; while(hi - lo > 1){ int mid = (lo + hi)/2; if(check(mid))hi = mid; else lo = mid; } cout << hi << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...