#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define xx first
#define yy second
#define endl "\n"
int n, p, q;
vector<int> arr;
//bool dp[110][110][110];
int dp[2010][2010];
int kolikoMala[2010], kolikoVelika[2010];
int prviManji(int x)
{
//cout<<endl<<x<<" e "<<arr[0]<<endl;
if (x<=arr[0]) return 0;
auto it=lower_bound(arr.begin(), arr.end(), x);
//cout<<endl<<arr[distance(arr.begin()-1, it)]<<" koji"<<endl;
return distance(arr.begin(), it)-1;
}
bool check(int w)
{
for (int i=0; i<n; i++)
{
auto it1=upper_bound(arr.begin(), arr.end(), arr[i]+w-1);
if (it1==arr.end()) { /*cout<<"ee"<<endl;*/ kolikoMala[i]=n-i; }
else kolikoMala[i]=(distance(arr.begin(), it1)-i);
auto it2=upper_bound(arr.begin(), arr.end(), arr[i]+2*w-1);
if (it2==arr.end()) { /*cout<<"ee"<<endl;*/ kolikoVelika[i]=n-i; }
else kolikoVelika[i]=(distance(arr.begin(), it2)-i);
//cout<<kolikoMala[i]<<" "<<kolikoVelika[i]<<endl;
}
for (int i=0; i<=p; i++)
{
for (int j=0; j<=q; j++)
{
dp[i][j]=-1;
if (i==0 && j==0) { dp[i][j]=-1; continue; }
if (i>0) dp[i][j]=max(dp[i][j], dp[i-1][j]+kolikoMala[dp[i-1][j]+1]);
if (j>0) dp[i][j]=max(dp[i][j], dp[i][j-1]+kolikoVelika[dp[i][j-1]+1]);
if (dp[i][j]>=n-1) { /*cout<<i<<" nasao "<<j<<" "<<dp[i][j]<<endl;*/ return true; }
}
}
return false;
}
/*bool check(int w)
{
for (int i=0; i<=p; i++) for (int j=0; j<=q; j++) dp[0][i][j]=true;
dp[0][0][0]=false;
for (int i=1; i<n; i++)
{
for (int j=0; j<=p; j++)
{
for (int k=0; k<=q; k++)
{
dp[i][j][k]=false;
//cout<<i<<" "<<prviManji(arr[i]-w+1)<<" "<<prviManji(arr[i]-2*w+1)<<endl;
if (j>0 && arr[i]-w+1<=arr[0]) dp[i][j][k]=true;
else if (j>0) dp[i][j][k]=max(dp[i][j][k], dp[prviManji(arr[i]-w+1)][j-1][k]);
if (k>0 && arr[i]-2*w+1<=arr[0]) dp[i][j][k]=true;
else if (k>0) dp[i][j][k]=max(dp[i][j][k], dp[prviManji(arr[i]-2*w+1)][j][k-1]);
}
}
}
return dp[n-1][p][q];
}*/
int bs()
{
int l=1, r=1000000000;
int ress=-1;
while (l<=r)
{
int mid=l+(r-l)/2;
//cout<<mid<<":"<<endl;
if (check(mid))
{
ress=mid;
r=mid-1;
}
else l=mid+1;
}
return ress;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>p>>q;
for (int i=0; i<n; i++)
{
int x; cin>>x; arr.pb(x);
}
sort(arr.begin(), arr.end());
if (p+q>=n) { cout<<1; exit(0); }
cout<<bs();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
15 ms |
1280 KB |
Output is correct |
9 |
Correct |
18 ms |
3712 KB |
Output is correct |
10 |
Correct |
27 ms |
8704 KB |
Output is correct |
11 |
Correct |
13 ms |
1056 KB |
Output is correct |
12 |
Correct |
81 ms |
8216 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
512 KB |
Output is correct |
15 |
Correct |
7 ms |
512 KB |
Output is correct |