This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
//#include<gondola.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <int, pi>
#define vi vector <int>
const ll mod = 998244353;
int n, p, q;
vector <int> w;
bool check(int d){
int a=p, b=q, cnt=0, cur=0;
while(a+b){
bool ctrl=1;
if(b){
if((*upper_bound(w.begin(), w.end(), w[cur]+d-1))<=w[cur]+2*d-1){
b--;
ctrl=0;
cur=upper_bound(w.begin(), w.end(), w[cur]+2*d-1)-w.begin();
}
}
if(a && ctrl){
a--;
ctrl=0;
cur=upper_bound(w.begin(), w.end(), w[cur]+d-1)-w.begin();
}
if(b && ctrl){
b--;
ctrl=0;
cur=upper_bound(w.begin(), w.end(), w[cur]+2*d-1)-w.begin();
}
if(cur>=n) return 1;
}
return 0;
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
cin>>n>>p>>q;
for(int i=1; i<=n; i++){
int x;
cin>>x;
w.pb(x);
}
int l=0, r=1e9+1;
sort(w.begin(), w.end());
//w.pb(1000000001);
while(r-l>1){
int mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid;
}
cout<<r;
}
Compilation message (stderr)
watching.cpp: In function 'bool check(int)':
watching.cpp:19:19: warning: unused variable 'cnt' [-Wunused-variable]
int a=p, b=q, cnt=0, cur=0;
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |