#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll int
#define tc ll test;cin >> test;while(test--)
#define vi vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define INF 1e18
#define MOD 1000000007
#define ff first
#define ss second
#define in >>
#define out <<
#define space << " " <<
#define spacef << " "
#define fo(i,a,b) for(ll i = a; i <= b; i++)
#define nextline out "\n"
#define print(x) for(auto i : x ) cout out i spacef
#define mmax(x,i) x = max(x,i)
#define mmin(x,i) x = min(x,i)
#define N 2005
ll n;
vi a(N);
bool check(ll w , ll p , ll q){
ll dp[n+5][p+5];
// dp[i][j] = minimum number of large cameras needed till i if we use j small cameras
// base case :
fo(i,0,p) dp[0][i] = 0;
fo(i,1,n){
auto it = lower_bound(a.begin()+1,a.begin()+n+1,a[i]-2*w+1);
ll pos = it-a.begin();
dp[i][0] = dp[pos-1][0]+1;
}
// recursive relation :
fo(i,1,n){
fo(j,1,p){
auto low1 = lower_bound(a.begin()+1,a.begin()+n+1,a[i]-w+1);
ll pos1 = low1-a.begin();
dp[i][j] = dp[pos1-1][j-1];
auto low2 = lower_bound(a.begin()+1,a.begin()+n+1,a[i]-2*w+1);
ll pos2 = low2-a.begin();
mmin(dp[i][j],dp[pos2-1][j]+1);
}
}
return dp[n][p] <= q;
}
int main() {
fast;
ll p,q;
cin in n in p in q;
if(p+q >= n){
cout out "1";
return 0;
}
fo(i,1,n) cin in a[i];
sort(a.begin()+1,a.begin()+n+1);
ll low = 1 , high = a[n];
ll ans;
while(low <= high){
ll mid = (low+high)/2;
if(check(mid,p,q)){
ans = mid;
high = mid-1;
}
else{
low = mid+1;
}
}
cout out ans;
return 0;
}
Compilation message
watching.cpp: In function 'int main()':
watching.cpp:95:14: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
95 | cout out ans;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
4 ms |
204 KB |
Output is correct |
12 |
Correct |
3 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
23 ms |
464 KB |
Output is correct |
8 |
Correct |
174 ms |
1328 KB |
Output is correct |
9 |
Correct |
992 ms |
6264 KB |
Output is correct |
10 |
Execution timed out |
1038 ms |
15252 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |