제출 #1310989

#제출 시각아이디문제언어결과실행 시간메모리
1310989ninstroyer구경하기 (JOI13_watching)C++20
100 / 100
102 ms16176 KiB
#include<bits/stdc++.h> using namespace std; const int nx = 2e3+5; int n,p,q,arr[nx],dp[nx][nx]; bool ok(int x) { memset(dp, 0x3f, sizeof dp); dp[0][0] = 0; for(int i = 1; i <= n; i++) { int l = upper_bound(arr+1,arr+1+i,arr[i]-x)-arr-1; int r = upper_bound(arr+1,arr+1+i,arr[i]-2*x)-arr-1; dp[i][0] = dp[r][0]+1; for(int j = 1; j <= min(i,p); j++) { dp[i][j] = dp[i][j-1]; dp[i][j] = min({dp[i][j], dp[l][j-1], dp[r][j]+1}); } } return dp[n][min(n,p)] <= q; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>p>>q; for(int i = 1; i <= n; i++) cin>>arr[i]; sort(arr+1,arr+1+n); int l = 1, r = 1e9+5; while(l<r) { int mid = (l+r)/2; if(ok(mid)) r = mid; else l = mid+1; } cout<<l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...