제출 #895529

#제출 시각아이디문제언어결과실행 시간메모리
895529nbphong구경하기 (JOI13_watching)C++14
50 / 100
1008 ms16276 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e3+10; int n,p,q,a[MAXN]; namespace sub12 { int dp[MAXN][MAXN]; bool check(int w) { memset(dp,0x3f,sizeof(dp)); dp[0][0] = 0; for(int i=1;i<=n;i++) for(int j=0;j<=p;j++) { int i1 = lower_bound(a+1,a+i,a[i]-w+1) - a; int i2 = lower_bound(a+1,a+i,a[i]-w-w+1) - a; if(j > 0) dp[i][j] = min(dp[i][j], dp[i1-1][j-1]); dp[i][j] = min(dp[i][j], dp[i2-1][j] + 1); } for(int i=0;i<=p;i++) if(dp[n][i] <= q) return 1; return 0; } } bool check(int w) { return sub12::check(w); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("EVENTS.INP","r",stdin); // freopen("EVENTS.OUT","w",stdout); cin >> n >> p >> q; for(int i=1;i<=n;i++) cin >> a[i]; sort(a+1,a+n+1); if(p+q > n) return cout << 1 << '\n',0; int l = 1, r = a[n]-a[1]+1, ans = -1; while(l <= r) { int mid = (l + r) >> 1; if(check(mid)) { r = mid-1; ans = mid; } else l = mid+1; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...