제출 #252424

#제출 시각아이디문제언어결과실행 시간메모리
252424c4ts0up구경하기 (JOI13_watching)C++17
0 / 100
2 ms384 KiB
/* 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; while (i<n) { // no podemos continuar if (!qres && !pres) return false; // podemos tomar uno largo if (qres) { while (j+1<n && arr[j+1]-arr[i]+1 <= 2*w) j++ } } } //*/ 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]+1<=w) j++; // revisa si el siguiente elemento está en el rango deseado if (j+1<n && arr[j+1]-arr[i]+1<=2*w) { while (j+1<n && arr[j+1]-arr[i]+1<=2*w) j++; } //cerr << "; j = " << j << endl; // si debemos usar una q if (w < arr[j]-arr[i]+1 && arr[j]-arr[i]+1 <= 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...