Artifact Content
Not logged in

Artifact 7020edc648386e31b55844f7bfad802b95c32f04


#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>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;

class FoxPaintingBalls { public:
	long long theMax(long long R, long long G, long long B, int N_)
	{
		LL N = N_;
		LL tot = N*(N+1)/2;
		LL t = tot/3;
		LL tr = tot%3;
		// (t,t,t+tr)

		LL l=0, r=(R+G+B)/tot+1; // [l,r)
		while( l+1 < r ) {
			LL c = (l+r)/2;
			LL rr = R-t*c;
			LL gg = G-t*c;
			LL bb = B-t*c;
			bool can = true;
			if(rr<0 || gg<0 || bb<0)
				can = false;
			else
				can = (rr+gg+bb >= tr*c);
			(can ? l : r) = c;
		}
		return l;
	}
};

// 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(_, FoxPaintingBalls().theMax(R, G, B, N));}
int main(){

CASE(0)
	long long R = 2LL; 
	long long G = 2LL; 
	long long B = 2LL; 
	int N = 3; 
	long long _ = 1LL; 
END
CASE(1)
	long long R = 1LL; 
	long long G = 2LL; 
	long long B = 3LL; 
	int N = 3; 
	long long _ = 0LL; 
END
CASE(2)
	long long R = 8LL; 
	long long G = 6LL; 
	long long B = 6LL; 
	int N = 4; 
	long long _ = 2LL; 
END
CASE(3)
	long long R = 7LL; 
	long long G = 6LL; 
	long long B = 7LL; 
	int N = 4; 
	long long _ = 2LL; 
END
CASE(4)
	long long R = 100LL; 
	long long G = 100LL; 
	long long B = 100LL; 
	int N = 4; 
	long long _ = 30LL; 
END
CASE(5)
	long long R = 19330428391852493LL; 
	long long G = 48815737582834113LL; 
	long long B = 11451481019198930LL; 
	int N = 3456; 
	long long _ = 5750952686LL; 
END
CASE(6)
	long long R = 1LL; 
	long long G = 1LL; 
	long long B = 1LL; 
	int N = 1; 
	long long _ = 3LL; 
END
CASE(7)
	long long R = 1LL; 
	long long G = 1LL; 
	long long B = 1LL; 
	int N = 7; 
	long long _ = -1LL; 
END
CASE(8)
	long long R = 1000000000000000000LL; 
	long long G = 1000000000000000000LL; 
	long long B = 1000000000000000000LL; 
	int N = 1; 
	long long _ = 3000000000000000000LL; 
END
}
// END CUT HERE