#include <bits/stdc++.h>
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define ppb pop_back()
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
using namespace std;
/*int tx[4] = {0,0,1,-1};
int ty[4] = {1,-1,0,0};
char t[4] = {'R','L','D','U'};
*/
int n,p,q;
vector<int> v;
vector<pii> dp; // choice : w or 2w
bool process(int pos,int w, int np,int nq)
{
if(pos==n) return 1;
if(np==p && nq==q) return 0;
//w
if(np<p)
{
int curr = w+v[pos]-1;
int l=0,r=n;
while(l+1<r)
{
int mid = (l+r)/2;
if(curr<v[mid])
r=mid;
else l=mid;
}
dp[pos].fi = process(r,w,np+1,nq);
}
//2w
if(nq<q)
{
int curr = 2*w+v[pos]-1;
int l=0,r=n;
while(l+1<r)
{
int mid = (l+r)/2;
if(curr<v[mid])
r=mid;
else l=mid;
}
dp[pos].se = process(r,w,np,nq+1);
}
return dp[pos].se==1 || dp[pos].fi==1;
}
bool good(int w)
{
// cout<<w<<" "<<process(0,w,0,0)<<endl;
dp.assign(n,{-1,-1});
return process(0,w,0,0);
}
int main()
{
cin>>n>>p>>q;
r(i,n)
{
int ev; cin>>ev;
v.pb(ev);
}
sort(v.begin(),v.end());
int l=0,r=3334; // r is true , l is false
while(l+1<r)
{
int m = (l+r)/2;
dp.assign(n,{-1,-1});
if(good(m))
{
r=m;
}
else
{
l=m;
}
}
cout<<r<<endl;
return 0;
}
# |
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 |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |