This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll,ll>
#define F first
#define S second
#define double long double
#define all(x) (x).begin(),(x).end()
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll , null_type , less_equal<ll> ,rb_tree_tag ,tree_order_statistics_node_update >ordered_set;
const int MOD = 1e9 + 7;
const int N=1e6 + 7 ;
const ll INF= 1e18+10;
struct trp{ll F,S,T;};
ll po1(ll x,ll y)
{
ll ans = 1;
while(y){
if( y & 1 ) ans *=x;
y /= 2;
x *=x;
x %= MOD;
ans %= MOD;
}
return ans;
}
ll n , p , q;
ll a[N];
ll dp[2005][2005];
bool ok(ll w)
{
for(ll i= 0; i <= p ; i ++) dp[0][i] = 0;
for(ll i= 1 ; i <= n ; i ++){
ll ans1 = -1;
ll ans2 = -1;
for(ll j = 1 ; j <= i ; j ++){
if(ans1 == -1 && a[i] - a[j] + 1<= w){
ans1 = j;
}
if(ans2 == -1 && a[i] - a[j] + 1 <= 2 * w) ans2 = j;
}
dp[i][0] = dp[ans2 - 1][0] + 1;
if(w == 1 && i == 2) cout << ans2 << endl;
for(ll j = 1 ; j <= p ; j ++){
dp[i][j] = min(dp[ans1-1][j-1] , dp[ans2 - 1][j] + 1);
}
}
return dp[n][p] <= q;
}
void solve()
{
cin >> n >> p >> q;
for(ll i=1 ;i <= n ; i++) cin >> a[i];
sort(a + 1 , a + n + 1);
if(p+q >= n){
cout << 1 <<endl;
return;
}
ll l = 1 , r = MOD , mid;
while(l < r){
mid = (l + r)/2;
if(ok(mid)) r = mid;
else l = mid + 1;
}
cout << l << endl;
}
int main(){
//ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(".in" , "r" , stdin);freopen(".out" , "w" , stdout);
int t = 1;
//cin >> t;
while(t--) {solve() ; }
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |