# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35031 | dqhungdl | Watching (JOI13_watching) | C++14 | 519 ms | 17724 KiB |
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>
using namespace std;
int n,P,Q,a[2005],f[2005][2005];
bool Check(int w)
{
for(int i=0;i<=n;i++)
for(int j=0;j<=P;j++)
f[i][j]=1e9;
f[0][0]=0;
for(int i=1;i<=n;i++)
{
int id1,id2;
for(int j=1;j<=i;j++)
if(a[i]-a[j]+1<=w)
{
id1=j;
break;
}
for(int j=1;j<=i;j++)
if(a[i]-a[j]+1<=2*w)
{
id2=j;
break;
}
for(int j=1;j<=P;j++)
f[i][j]=min(f[i][j],f[id1-1][j-1]);
for(int j=0;j<=P;j++)
f[i][j]=min(f[i][j],f[id2-1][j]+1);
}
for(int j=0;j<=P;j++)
if(f[n][j]<=Q)
return true;
return false;
}
int main()
{
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);
int res,l=1,r=1e9;
while(l<=r)
{
int mid=(l+r)/2;
if(Check(mid)==true)
{
res=mid;
r=mid-1;
}
else
l=mid+1;
}
cout<<res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |