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>
#define INF 1000000005
using namespace std;
pair <int,int> din[2005][2005];
int n,mici,mari,v[2005],st,dr,mij,i,sol;
bool verif (int val)
{
int i,j,lung,dr;
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
din[i][j]={INF,INF};
}
}
for (lung=1;lung<=n;lung++)
{
for (i=1;i<=n-lung+1;i++)
{
dr=i+lung-1;
din[i][dr]={INF,INF};
if (v[dr]-v[i]+1<=val)
{
if (mici!=0)
{
din[i][dr]=min(din[i][dr],{0,1});
}
}
if (v[dr]-v[i]+1<=2*val)
{
if (mari!=0)
{
din[i][dr]=min(din[i][dr],{1,0});
}
}
for (j=i;j<=dr-1;j++)
{
if (din[i][j].first+din[j+1][dr].first<=mari&&din[i][j].second+din[j+1][dr].second<=mici)
{
din[i][dr]=min(din[i][dr],{din[i][j].first+din[j+1][dr].first,din[i][j].second+din[j+1][dr].second});
}
}
}
}
if (din[1][n].first!=INF&&din[1][n].second!=INF)
{
return 1;
}
return 0;
}
int main()
{
#ifdef HOME
ifstream cin("date.in");
ofstream cout("date.out");
#endif // HOME
cin>>n>>mici>>mari;
for (i=1;i<=n;i++)
{
cin>>v[i];
}
sort (v+1,v+n+1);
st=1;
dr=1000000000;
while (st<=dr)
{
mij=(st+dr)/2;
if (verif(mij)==1)
{
sol=mij;
dr=mij-1;
}
else
{
st=mij+1;
}
}
cout<<sol;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |