이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
ID:
LANG: C++
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define ff first
#define ss second
const int NMAX = 2e3+2, PMAX = 1e5+2;
ll n, p, q;
vector <ll> arr;
bool Check(ll w) {
int i = 0, pres = p, qres = q, j;
//cerr << "---" << endl << "w = " << w << endl;
while (i<n) {
//cerr << "i = " << i << "; pres = " << pres << "; qres = " << qres;
j = i;
while (j+1<n && arr[j+1]-arr[i]<w) j++;
// revisa si el siguiente elemento está en el rango deseado
if (j+1<n && arr[j+1]-arr[i]<2*w) {
while (j+1<n && arr[j+1]-arr[i]<2*w) j++;
}
//cerr << "; j = " << j << endl;
// si debemos usar una q
if (w <= arr[j]-arr[i] && arr[j]-arr[i] < 2*w) {
//cerr << "Entro aca" << endl;
// si tenemos q
if (qres) qres--;
// si solo tenemos p
else if (pres >= 2) pres-=2;
// si no tenemos suficientes p ni q
else {
//cerr << "FAIL" << endl;
return false;
}
}
// si debemos usar una p
else if (pres) pres--;
// no tenemos suficiente, así que usamos q
else if (qres) qres--;
// no se puede, no hay tortillas
else {
//cerr << "FAIL" << endl;
return false;
}
i = j+1;
}
//cerr << "OK" << endl;
return true;
}
int main() {
/*//
freopen("watching.in", "r", stdin);
freopen("", "w", stdout);
//*/
cin >> n >> p >> q;
arr.resize(n);
for (int i=0; i<n; i++) cin >> arr[i];
sort(arr.begin(), arr.end());
/*//
cerr << "A: [";
for (int x : arr) cerr << x << ", ";
cerr << "]" << endl;
//*/
ll lb = 1, ub = 1e9, mid;
while (lb <= ub) {
mid = (lb+ub)/2;
if (Check(mid)) ub = mid-1;
else lb = mid+1;
}
cout << ub+1 << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |