Artifact Content
Not logged in

Artifact cbc7da6c8638afb4040f558e44a184a6b83483eb


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class ProblemSets { public:
	long long maxSets(long long E, long long EM, long long M, long long MH, long long H)
	{
		LL L=0, R=0x7fffffffffffffffLL; // can make [L,R)
		while(R-L>1) {
			LL C = L+(R-L)/2;
			(can(E,EM,M,MH,H,C) ? L : R) = C;
		}
		return L;
	}

	bool can(long long E, long long EM, long long M, long long MH, long long H, LL nProbs) {
		LL eNeed = max(0LL, nProbs-E);
		LL mNeed = max(0LL, nProbs-M);
		LL hNeed = max(0LL, nProbs-H);
		if(EM < eNeed) return false;
		EM -= eNeed;
		if(MH < hNeed) return false;
		MH -= hNeed;
		return mNeed <= EM+MH;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const long long& Expected, const long long& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, ProblemSets().maxSets(E, EM, M, MH, H));}
int main(){

CASE(0)
	long long E = 2LL; 
	long long EM = 2LL; 
	long long M = 1LL; 
	long long MH = 2LL; 
	long long H = 2LL; 
	long long _ = 3LL; 
END
CASE(1)
	long long E = 100LL; 
	long long EM = 100LL; 
	long long M = 100LL; 
	long long MH = 0LL; 
	long long H = 0LL; 
	long long _ = 0LL; 
END
CASE(2)
	long long E = 657LL; 
	long long EM = 657LL; 
	long long M = 657LL; 
	long long MH = 657LL; 
	long long H = 657LL; 
	long long _ = 1095LL; 
END
CASE(3)
	long long E = 1LL; 
	long long EM = 2LL; 
	long long M = 3LL; 
	long long MH = 4LL; 
	long long H = 5LL; 
	long long _ = 3LL; 
END
CASE(4)
	long long E = 1000000000000000000LL; 
	long long EM = 1000000000000000000LL; 
	long long M = 1000000000000000000LL; 
	long long MH = 1000000000000000000LL; 
	long long H = 1000000000000000000LL; 
	long long _ = 1666666666666666666LL; 
END
/*
CASE(5)
	long long E = LL; 
	long long EM = LL; 
	long long M = LL; 
	long long MH = LL; 
	long long H = LL; 
	long long _ = LL; 
END
CASE(6)
	long long E = LL; 
	long long EM = LL; 
	long long M = LL; 
	long long MH = LL; 
	long long H = LL; 
	long long _ = LL; 
END
*/
}
// END CUT HERE