#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,p,q;
vector<int> Q;
int dp[1020][1020];
bool check(int ile)
{
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
dp[i][j]=1000000000;
dp[0][0]=0;
for(int i=1;i<=Q.size();i++)
{
int gdzie1=lower_bound(Q.begin(),Q.end(),Q[i-1]-2*ile+1)-Q.begin();
int gdzie2=lower_bound(Q.begin(),Q.end(),Q[i-1]-ile+1)-Q.begin();
for(int j=0;j<=n;j++)
{
if(j>0)
dp[i][j]=min(dp[gdzie1][j]+1,dp[gdzie2][j-1]);
else dp[i][j]=dp[gdzie1][j]+1;
}
}
for(int i=0;i<=n;i++)
if(dp[n][i]<=q)
return 1;
return 0;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>p>>q;
int x;
for(int i=1;i<=n;i++)
{
cin>>x;
Q.push_back(x);
}
sort(Q.begin(),Q.end());
int pocz=0,kon=1000000005,sre,ostd;
while(pocz<kon)
{
sre=(pocz+kon)/2;
if(check(sre))
{
ostd=sre;
kon=sre;
}
else pocz=sre+1;
}
cout<<ostd;
return 0;
}
Compilation message
watching.cpp: In function 'bool check(int)':
watching.cpp:14:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i=1;i<=Q.size();i++)
| ~^~~~~~~~~~
watching.cpp: In function 'int main()':
watching.cpp:54:11: warning: 'ostd' may be used uninitialized in this function [-Wmaybe-uninitialized]
54 | cout<<ostd;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
8660 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |