Submission #138016

#TimeUsernameProblemLanguageResultExecution timeMemory
138016MladenPWatching (JOI13_watching)C++17
100 / 100
469 ms31968 KiB
#include<bits/stdc++.h> #define STIZE(x) fprintf(stderr, "STIZE%d\n", x); #define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x); #define NL(x) printf("%c", " \n"[(x)]); #define lld long long #define pii pair<int,int> #define pb push_back #define fi first #define se second #define mid (l+r)/2 #define endl '\n' #define all(a) begin(a),end(a) #define sz(a) int((a).size()) #define LINF 1000000000000000LL #define INF 1000000000 #define EPS 1e-9 using namespace std; #define MAXN 2010 lld N, P, Q, A[MAXN]; lld dp[MAXN][MAXN], l1[MAXN], l2[MAXN]; bool check(lld w) { for(int i = 0; i <= N; i++) { for(int j = 0; j <= P; j++) dp[i][j] = INF; } for(int i = 1; i <= N; i++) { for(int j = i-1; j >= 0; j--) { if(A[j] <= A[i]-w && A[j+1] > A[i]-w) l1[i] = j; if(A[j] <= A[i]-2*w && A[j+1] > A[i]-2*w) l2[i] = j; } } for(int i = 0; i <= P; i++) dp[0][i] = 0; for(int i = 1; i <= N; i++) { for(int j = 0; j <= P; j++) { if(j > 0) dp[i][j] = min(dp[l1[i]][j-1], dp[l2[i]][j]+1); else dp[i][j] = dp[l2[i]][j]+1; } } for(int i = 0; i <= P; i++) if(dp[N][i] <= Q) return true; return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> N >> P >> Q; A[0] = -2000000000; for(int i = 1; i <= N; i++) cin >> A[i]; sort(A+1, A+1+N); if(P+Q >= N) { cout << 1 << endl; return 0; } lld l = 1, r = 1000000000, rez = r; while(l <= r) { if(check(mid)) rez = mid, r = mid-1; else l = mid+1; } cout << rez << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...