#include<bits/stdc++.h>
using namespace std;
#define task "watching"
#define lb lower_bound
#define ub upper_bound
#define ALL(v) (v).begin(),(v).end()
#define zs(v) int((v).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,b,a) for(int i=(b),_a=(a);i>=_a;--i)
#define FOR_(i,a,b) for(int i=(a),_b=(b);i<_b;++i)
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
const ll mod=1000000007; /// 998244353
const int base=311;
const int N=2e3+5;
int n,s,l,dp[N][N];
ll a[N];
int check(int val)
{
for(int i=0;i<=s;++i)
{
for(int j=0;j<=l;++j)
{
dp[i][j]=-1;
}
}
dp[0][0]=0;
for(int i=0;i<=s;++i)
{
for(int j=0;j<=l;++j)
{
if(dp[i][j]==-1) continue;
int l=dp[i][j]+1, r=n;
int id=-1;
while(l<=r)
{
int mid=(l+r)>>1;
if(a[mid]-a[dp[i][j]+1]+1<=val) id=mid, l=mid+1;
else r=mid-1;
}
dp[i+1][j]=max({dp[i][j],dp[i+1][j],id});
l=dp[i][j]+1, r=n;
id=-1;
while(l<=r)
{
int mid=(l+r)>>1;
if(a[mid]-a[dp[i][j]+1]+1<=2*val) id=mid, l=mid+1;
else r=mid-1;
}
dp[i][j+1]=max({dp[i][j],dp[i][j+1],id});
}
}
return dp[s][l]>=n;
}
void biot()
{
cin>>n>>s>>l;
if(s+l>=n)
{
cout<<1;
return;
}
for(int i=1;i<=n;++i) cin>>a[i];
sort(a+1,a+n+1);
int l=1, r=1e9, ans=0;
// cout<<check(16)<<endl;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
cout<<ans;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
biot();
}
Compilation message
watching.cpp: In function 'int main()':
watching.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
91 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
92 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 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 |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
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 |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
85 ms |
1280 KB |
Output is correct |
9 |
Correct |
95 ms |
3840 KB |
Output is correct |
10 |
Correct |
121 ms |
8696 KB |
Output is correct |
11 |
Correct |
106 ms |
1108 KB |
Output is correct |
12 |
Correct |
587 ms |
8108 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |