제출 #635245

#제출 시각아이디문제언어결과실행 시간메모리
635245Ronin13구경하기 (JOI13_watching)C++14
100 / 100
244 ms15992 KiB
#include<bits/stdc++.h> #define ll long long #define ull unsigned ll #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const int NMAX = 2e5 + 1; int a[NMAX]; bool slv(int w, int n, int p, int q){ int dp[n + 1][n + 1]; for(int i = 0; i <= n; i++){ for(int j = 0; j <= n; j++){ i == 0 ? dp[i][j] = 0 : dp[i][j] = q + 1; } } int ind1, ind2; ind1 = ind2 = 0; for(int i = 1; i <= n; i++){ while(a[i] - a[ind1] >= w) ind1++; while(a[i] - a[ind2] >= 2 * w) ind2++; for(int j = 0; j <= n; j++){ dp[i][j] = dp[ind2 - 1][j] + 1; if(j) dp[i][j] = min(dp[i][j], dp[ind1 - 1][j - 1]); } } return dp[n][p] <= q; } int main(){ int n; cin >> n; int p, q; cin >> p >> q; for(int i = 1; i <= n; i++) cin >> a[i]; a[0] = -1e9; sort(a + 1, a + 1 + n); if(p + q >= n){ cout << 1 << "\n"; return 0; } int l = 0, r = 1e9 + 5; while(l + 1 < r){ int mid = (l + r) / 2; if(slv(mid, n, p, q)) r= mid; else l = mid; } cout << r; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...