#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
int n;
vector<int> v;
vector<vector<int>> dp;
int f(int pos,int q,int w){
if(q < 0) return 1e18;
if(pos >= n) return 0;
if(dp[pos][q] != 1e18) return dp[pos][q];
int a = lower_bound(all(v), v[pos] + w) - v.begin();
int b = lower_bound(all(v), v[pos] + 2*w) - v.begin();
dp[pos][q] = min(f(a,q,w) + 1,f(b,q-1,w));
return dp[pos][q];
}
void solve(){
int p,q;
cin >> n >> p >> q;
v.assign(n,0);
for(int i=0;i<n;i++){
cin >> v[i];
}
if(p + q >= n){
cout << 1 << endl;
return;
}
auto check = [&](int m){
dp.assign(n,vector<int>(q+1,1e18));
return f(0,q,m) <= p;
};
sort(all(v));
int l = 1,r = 1e9;
while(l < r){
int m = (l + r) / 2;
if(check(m)) r = m;
else l = m + 1;
}
cout << l << endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
}
Compilation message
watching.cpp: In function 'int f(int, int, int)':
watching.cpp:16:19: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
16 | if(q < 0) return 1e18;
| ^~~~
watching.cpp: In lambda function:
watching.cpp:41:31: warning: overflow in conversion from 'double' to 'std::vector<int>::value_type' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
41 | dp.assign(n,vector<int>(q+1,1e18));
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |