#include<bits/stdc++.h>
using namespace std;
const int nmax=2e3+42;
int n,p,q,inp[nmax];
int would_go_small[nmax],would_go_big[nmax];
int dp[nmax][nmax];
int rec(int p_now,int q_now)
{
if(p_now==0&&q_now==0)return 1;
if(dp[p_now][q_now]!=-1)return dp[p_now][q_now];
int ret=0,current;
if(p_now)
{
current=would_go_small[rec(p_now-1,q_now)];
ret=max(ret,current);
}
if(q_now)
{
current=would_go_big[rec(p_now,q_now-1)];
ret=max(ret,current);
}
dp[p_now][q_now]=ret;
return ret;
}
bool can(int w)
{
for(int i=1;i<=n;i++)
{
would_go_small[i]=lower_bound(inp+1,inp+n+1,inp[i]+w)-inp;
would_go_big[i]=lower_bound(inp+1,inp+n+1,inp[i]+2*w)-inp;
//cout<<i<<" -> "<<would_go_small[i]<<" "<<would_go_big[i]<<endl;
}
would_go_big[n+1]=n+1;
would_go_small[n+1]=n+1;
memset(dp,-1,sizeof(dp));
return rec(p,q)>n;
}
int main()
{
scanf("%i%i%i",&n,&p,&q);
p=min(p,n);
q=min(q,n);
for(int i=1;i<=n;i++)scanf("%i",&inp[i]);
sort(inp+1,inp+n+1);
int ok=1e9/3+1,not_ok=0;
while(ok-not_ok>1)
{
int av=(ok+not_ok)/2;
if(can(av))ok=av;
else not_ok=av;
}
printf("%i\n",ok);
return 0;
}
Compilation message
watching.cpp: In function 'int main()':
watching.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i%i",&n,&p,&q);
~~~~~^~~~~~~~~~~~~~~~~~~
watching.cpp:53:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++)scanf("%i",&inp[i]);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
16640 KB |
Output is correct |
2 |
Correct |
67 ms |
16640 KB |
Output is correct |
3 |
Correct |
71 ms |
16640 KB |
Output is correct |
4 |
Correct |
65 ms |
16640 KB |
Output is correct |
5 |
Correct |
65 ms |
16640 KB |
Output is correct |
6 |
Correct |
68 ms |
16640 KB |
Output is correct |
7 |
Correct |
67 ms |
16640 KB |
Output is correct |
8 |
Correct |
66 ms |
16640 KB |
Output is correct |
9 |
Correct |
64 ms |
16640 KB |
Output is correct |
10 |
Correct |
65 ms |
16640 KB |
Output is correct |
11 |
Correct |
66 ms |
16640 KB |
Output is correct |
12 |
Correct |
72 ms |
16640 KB |
Output is correct |
13 |
Correct |
78 ms |
16696 KB |
Output is correct |
14 |
Correct |
65 ms |
16640 KB |
Output is correct |
15 |
Correct |
67 ms |
16640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
16692 KB |
Output is correct |
2 |
Correct |
69 ms |
16692 KB |
Output is correct |
3 |
Correct |
653 ms |
16792 KB |
Output is correct |
4 |
Correct |
112 ms |
16768 KB |
Output is correct |
5 |
Correct |
110 ms |
16768 KB |
Output is correct |
6 |
Execution timed out |
1042 ms |
16888 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |