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 <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
int32_t main(){
int n, p, q;
cin>>n>>p>>q;
int a[n];
for(int i = 0;i<n;i++) cin>>a[i];
//cout<<"DONE WITH INPUT"<<endl;
sort(a, a+n);
int u = 1e9;
int l = 1;
int mini = 1e9;
while(u>=l){
int m = (l+u)/2;
//cout<<m<<endl;
int covered = n;
int p1 = p, q1 = q;
int b[n];
for(int i = 0;i<n;i++) b[i] = a[i];
while(q1 && covered>0){
pair<int, int> count = make_pair(0, 0);
int j = 1;
for(int i = 0;i<covered;i++){
while(j<covered && b[j]<(2*m+b[i])) j++;
if(count.first<(j-i)) count = make_pair(j-i, i);
i = j-1;
}
//cout<<(covered-count.first)<<" ARE STILL LEFT"<<endl;
for(int i = count.second;(i+count.first)<covered;i++){
b[i] = b[i+count.first];
}
//cout<<"PRINTING ARRAY: ";
covered-=count.first;
//for(int i = 0;i<covered;i++) cout<<b[i]<<" ";
//cout<<endl;
q1--;
}
while(p1 && covered>0){
pair<int, int> count = make_pair(0, 0);
int j = 1;
for(int i = 0;i<covered;i++){
while(j<covered && b[j]<(m+b[i])) j++;
if(count.first<(j-i)) count = make_pair(j-i, i);
i = j-1;
}
//cout<<(covered-count.first)<<" ARE STILL LEFT"<<endl;
for(int i = count.second;(i+count.first)<covered;i++){
b[i] = b[i+count.first];
}
//cout<<"PRINTING ARRAY: ";
covered-=count.first;
//for(int i = 0;i<covered;i++) cout<<b[i]<<" ";
//cout<<endl;
p1--;
}
//cout<<l<<" "<<u<<" "<<m<<" "<<covered<<endl;
if(covered==0){
u = m-1;
mini = min(m, mini);
}
else{
l = m+1;
}
}
cout<<mini<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |