이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#define MAX 2002
using namespace std;
int n,p,q,a[MAX];
bool check(int w){
int cap = a[1]+w-1;
int nrp = 1, nrq = 0;
for(int i = 2; i <= n; i++){
if(a[i] <= cap){
continue;
}else{
if(nrp < p){
cap = a[i]+w-1;
nrp++;
}else{
if(nrq < q){
cap = a[i]+2*w-1;
nrq++;
}else{
return false;
}
}
}
}
return true;
}
int main()
{
cin >> n >> p >> q;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a+1, a+n+1);
int st = 1, dr = a[n];
int ans = 0;
/// 0 0 0 0 1 1 1 1 1
/// ^
while(st <= dr){
int mid = (st+dr)/2;
if(check(mid)){
ans = mid;
dr = mid-1;
}else{
st = mid+1;
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |