Submission #161996

#TimeUsernameProblemLanguageResultExecution timeMemory
161996nvmdavaWatching (JOI13_watching)C++17
100 / 100
162 ms16160 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define pb push_back mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define N 2005 #define INF 0x3f3f3f3f3f3f3f3f #define MOD 1000000007LL int a[N]; int dp[N][N]; int n, p, q; bool check(int w){ int l = 0, r = 0; for(int i = 1; i <= n; i++){ while(a[i] - w >= a[l + 1]) ++l; while(a[i] - 2 * w >= a[r + 1]) ++r; dp[i][0] = dp[r][0] - 1; for(int j = 1; j <= p; j++){ dp[i][j] = max(dp[l][j - 1], dp[r][j] - 1); } } return dp[n][p] >= 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>p>>q; for(int i = 0; i <= p; i++) dp[0][i] = q; if(p + q >= n){ cout<<1; return 0; } for(int i = 1; i <= n; i++) cin>>a[i]; sort(a + 1, a + 1 + n); int l = 1, r = 1000000000; while(l != r){ int m = (l + r) >> 1; if(check(m)) r = m; else l = m + 1; } cout<<r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...