#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 |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
177 ms |
504 KB |
Output is correct |
4 |
Correct |
78 ms |
376 KB |
Output is correct |
5 |
Correct |
85 ms |
404 KB |
Output is correct |
6 |
Correct |
88 ms |
440 KB |
Output is correct |
7 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |