# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870145 | Eliorita | Watching (JOI13_watching) | C++14 | 295 ms | 32088 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>
#define int long long
#define pb push_back
#define x first
#define y second
#define getbit(u,i) ((u>>i)&1)
#define all(x) x.begin(),x.end()
#define N 200001
using namespace std;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
int n,a,b,A[N],dp[2001][2001],ans,l=1,r=1e9+8;
bool check(int x)
{
int mn=LLONG_MAX;
memset(dp,0x3f,sizeof(dp));
dp[0][0]=0;
for(int i=1;i<=n;i++)
{
int l=1,r=1;
while(l<i&&A[i]>=x+A[l]) l++;
for(int j=0;j<=b;j++) dp[i][j]=dp[l-1][j]+1;
while(r<i&&A[i]>=2*x+A[r]) r++;
for(int j=0;j<=b;j++) dp[i][j+1]=min(dp[i][j+1],dp[r-1][j]);
}
for(int i=0;i<=b;i++) mn=min(mn,dp[n][i]);
return mn<=a;
}
signed main()
{
if(fopen("paint.inp","r"))
{
freopen("paint.inp","r",stdin);
freopen("paint.out","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>a>>b;
if(n<=a+b) {cout<<1; return 0;}
for(int i=1;i<=n;i++) cin>>A[i];
sort(A+1,A+n+1);
while(l<=r)
{
int m=(l+r)/2;
if(check(m))
{
ans=m;
r=m-1;
}
else l=m+1;
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |