Submission #587772

#TimeUsernameProblemLanguageResultExecution timeMemory
587772MohamedFaresNebiliWatching (JOI13_watching)C++14
100 / 100
383 ms31820 KiB
#include <bits/stdc++.h> /// #pragma GCC optimize ("Ofast") /// #pragma GCC target ("avx2") /// #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using ii = pair<ll, ll>; using vi = vector<int>; #define ff first #define ss second #define pb push_back #define all(x) (x).begin(), (x).end() #define lb lower_bound #define int ll const int MOD = 1000 * 1000 * 1000 + 7; int N, P, Q, A[2001], DP[2001][2001]; int solve(int v) { int X[N], Y[N]; for(int l = 0, i = 0; l < N; l++) { while(A[l] - A[i] >= v) i++; X[l] = i; } for(int l = 0, i = 0; l < N; l++) { while(A[l] - A[i] >= 2 * v) i++; Y[l] = i; } for(int l = 0; l <= N; l++) for(int i = 0; i <= P; i++) DP[l][i] = 1e9 + 7; DP[0][0] = 0; for(int l = 1; l <= N; l++) { for(int i = 0; i <= P; i++) { if(i > 0) DP[l][i] = min(DP[l][i], DP[X[l - 1]][i - 1]); if(DP[Y[l - 1]][i - 1] != 1e9 + 7) DP[l][i] = min(DP[l][i], DP[Y[l - 1]][i] + 1); } } for(int l = 0; l <= P; l++) if(DP[N][l] <= Q) return 1; return 0; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> P >> Q; P = min(P, N), Q = min(Q, N); for(int l = 0; l < N; l++) cin >> A[l]; sort(A, A + N); int lo = 1, hi = 1e9, res = 1e9 + 7; while(lo <= hi) { int md = (lo + hi) / 2; if(solve(md)) hi = md - 1, res = md; else lo = md + 1; } cout << res << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...