# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95127 | figter001 | Watching (JOI13_watching) | C++14 | 3 ms | 376 KiB |
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>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 1e5+50;
const int M = 1e6;
const ll oo = 1e18;
const int mod = 1e9+7;
vector<int> a;
int n,p,q;
bool can(int w){
int s = p,b = q;
for(int i=0;i<n;i++){
int md,lo=i,hi=n-1,f = i;
while(lo <= hi){
int md = (lo+hi)/2;
if(a[md] - a[i] + 1 <= 2*w){
lo = md+1;
f = md;
}else hi = md-1;
}
lo = i;hi=n-1;
int f2 = i;
while(lo <= hi){
int md = (lo+hi)/2;
if(a[md] - a[i] + 1 <= w){
lo = md+1;
f2 = md;
}else hi = md-1;
}
if(!s && !b)return 0;
if(!s){
b--;
i = f;
}else if(!b){
s--;
i = f2;
}else if(f == f2){
s--;
i = f2;
}else if(f > f2){
b--;
i = f;
}
if(i == n-1)return 1;
}
return 0;
}
int main(){
cin>>n>>p>>q;
a.resize(n);
for(int i=0;i<n;i++)cin>>a[i];
sort(a.begin(),a.end());
ll md,lo=0,hi=1e9,ans = 1e9;
while(lo <= hi){
md = (lo+hi)/2;
if(can(md)){
hi = md-1;
ans = md;
}else lo = md+1;
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |