Submission #252242

# Submission time Handle Problem Language Result Execution time Memory
252242 2020-07-25T02:43:56 Z c4ts0up Watching (JOI13_watching) C++17
0 / 100
2 ms 384 KB
/*
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) {
			// si tenemos q
			if (qres) qres--;
			// si solo tenemos p
			else if (pres >= 2) pres-=2;
			// si no tenemos suficientes p ni q
			else 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 return false;
		
		i = j+1;
	}
	
	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 << mid << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -