This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define db long double
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
const int sz = 2e3 + 5;
int n, p, q, dp[sz][sz], a[sz];
int check(int w){
for(int i = 1; i <= n; i++){
int i1 = 0, i2 = 0;
int l = 1, r = i - 1;
while(l <= r){
int mid = (l + r) / 2;
if(a[mid] + w <= a[i]){
i1 = mid;
l = mid + 1;
}
else{
r = mid - 1;
}
}
l = 1, r = i - 1;
while(l <= r){
int mid = (l + r) / 2;
if(a[mid] + 2 * w <= a[i]){
i2 = mid;
l = mid + 1;
}
else{
r = mid - 1;
}
}
for(int j = 1; j <= p; j++){
// while(i1 + 1 <= n and a[i1 + 1] + w <= a[i]) i1++;
// while(i2 + 1 <= n and a[i2 + 1] + w * 2 <= a[i]) i2++;
dp[i][j] = min(dp[i2][j] + 1, i1 == 0 ? q + 1 : dp[i1][j - 1]);
}
}
ll ans = 1e9;
for (ll i = 0; i <= p; i++) ans = min(ans, dp[n][i]);
return ans;
}
void fmain(){
fastio;
cin >> n >> p >> q;
if(p + q >= n){
cout << 1;
return;
}
p = min(n, p), q = min(n, q);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a + 1, a + n + 1);
int l = 1, r = 1e9, res = -1;
while(l <= r){
int mid = (l + r) / 2;
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= p; j++) dp[i][j] = 0;
if(check(mid) <= q){
res = mid;
r = mid - 1;
}
else{
l = mid + 1;
}
}
cout << res;
}
signed main(){
int tmr = 1;
// cin >> tmr;
while(tmr--){
fmain();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |