#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 5001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 35;
ll n, p, q, pp, qq;
ll v[NMAX];
bool OK(ll w){
ll last = -1;
p = pp;
q = qq;
for(ll i = 1; i <= n; i++){
if(last <= v[i]){
ll idx = 0, pas = 1 << 12;
while(pas){
if(idx + pas <= n && v[idx + pas] <= v[i] + w)
idx += pas;
pas /= 2;
}
ll r = 0;
pas = (1 << 12);
while(pas){
if(r + pas <= n && v[r + pas] <= v[i] + 2 * w)
r += pas;
pas /= 2;
}
if(p == 0 && q == 0)
return 0;
if(p == 0){
q--;
last = v[i] + 2 * w;
}else if(q == 0){
p--;
last = v[i] + w;
}else{
if(idx == r){
last = v[i] + w;
p--;
}else{
last = v[i] + 2 * w;
q--;
}
}
}
}
return 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll i;
cin >> n >> p >> q;
pp = p;
qq = q;
for(i = 1; i <= n; i++){
cin >> v[i];
}
sort(v + 1, v + n + 1);
ll r = 0, pas = (1LL << 60);
while(pas){
if(!OK(r + pas))
r += pas;
pas /= 2;
}
cout << r + 1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
524 KB |
Output is correct |
5 |
Correct |
3 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |