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<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<bitset>
#include<chrono>
#include<random>
#include<ext/rope>
/* ordered_set
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 2000 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, p, q, a[maxN];
int f[maxN][maxN];
void ReadInput()
{
cin >> n >> p >> q;
p = min(p, n);
q = min(q, n);
for(int i=1; i<=n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
}
pair<int, int> cmp(pair<int, int> a, pair<int, int> b)
{
if(a.fi * 2 + a.se < b.fi * 2 + b.se) return a;
if(a.fi * 2 + a.se > b.fi * 2 + b.se) return b;
return a.fi > b.fi ? a : b;
}
bool chk(int x)
{
for(int i=1; i<=n; i++)
{
int t = i;
int id1 = lower_bound(a + 1, a + n + 1, a[i] - x + 1) - a;
int id2 = lower_bound(a + 1, a + n + 1, a[i] - x * 2 + 1) - a;
for(int j=0; j<=p; j++)
{
f[i][j] = oo;
f[i][j] = f[id2 - 1][j] + 1;
if(j > 0) f[i][j] = min(f[i][j], f[id1 - 1][j - 1]);
}
}
return f[n][p] <= q;
}
void Solve()
{
//chk(4);return;
int low = 1, high = 1e9, mid;
while(low <= high)
{
mid = (low + high) / 2;
if(chk(mid)) high = mid - 1;
else low = mid + 1;
}
cout << low;
}
int32_t main()
{
// freopen("x.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
Compilation message (stderr)
watching.cpp: In function 'bool chk(long long int)':
watching.cpp:57:13: warning: unused variable 't' [-Wunused-variable]
57 | int t = i;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |