Submission #107043

#TimeUsernameProblemLanguageResultExecution timeMemory
107043DiuvenWatching (JOI13_watching)C++14
100 / 100
213 ms16248 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lint; int n, p, q, A[2010]; int f(int x){ if(x<1) return 0; // A에서 x이하인 최대 인덱스. 없으면 0 int pos = upper_bound(A+1, A+n+1, x) - A - 1; return pos; } inline int _min(int x, int y){ return x<y ? x : y; } bool check(lint x){ static int D[2010][2010], E[2010], F[2010]; for(int i=1; i<=n; i++){ E[i] = f(A[i] - x); F[i] = f(A[i] - 2*x); } for(int i=1; i<=n; i++) D[0][i] = 0; for(int i=1; i<=n; i++){ int s = E[i], l = F[i]; D[i][0] = D[l][0] + 1; for(int j=1; j<=n; j++) D[i][j] = _min(D[s][j-1], D[l][j]+1); } // cout<<"SOLVE: "<<x<<'\n'; // for(int i=1; i<=n; i++, cout<<'\n') for(int j=1; j<=n; j++) cout<<D[i][j]<<' '; for(int i=0; i<=p; i++) if(D[n][i]<=q) return true; return false; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>p>>q; for(int i=1; i<=n; i++) cin>>A[i]; sort(A+1, A+n+1); int s = 1, e = 1e9; while(s<e){ int mid = (s+e)/2; if(check(mid)) e = mid; else s = mid+1; } cout<<s<<'\n'; /* D[i][j] : 1~i까지, j개 작은 카메라 썼을 때 큰 카메라 최소 수 D[i][j] = min(D[k][j-1], D[l][j]+1); */ return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...