Artifact Content
Not logged in

Artifact 4a688b8acc36f02dca6cbd06a14b49007689cce3


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

class CutSticks { public:
	double maxKth(vector <int> sticks, int Ct, int K) 
	{
		double L=0, R=1000000000;
		for(int n=0; n<1000; ++n)
		{
			double C = (L+R)/2;

			// can we create K sticks of length C from sticks within Ct cuts?
			int cnt = 0;
			int ncut = 0;
			for(int i=0; i<sticks.size(); ++i) {
				int ct = int( sticks[i] / C )-1;
				if( ct >= 0 ) {
					ct = min(ct, Ct-ncut);
					ncut += ct;
					cnt += ct+1;
				}
			}

			(cnt >= K ? 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 double& Expected, const double& Received) {
 double diff = Expected - Received; if (diff < 0) diff = -diff; bool ok = (diff < 1e-9);
 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(_, CutSticks().maxKth(sticks, C, K));}
int main(){

CASE(0)
	int sticks_[] = {5, 8};
	  vector <int> sticks(sticks_, sticks_+sizeof(sticks_)/sizeof(*sticks_)); 
	int C = 1; 
	int K = 1; 
	double _ = 8.0; 
END
CASE(1)
	int sticks_[] = {5, 8};
	  vector <int> sticks(sticks_, sticks_+sizeof(sticks_)/sizeof(*sticks_)); 
	int C = 1; 
	int K = 2; 
	double _ = 5.0; 
END
CASE(2)
	int sticks_[] = {5, 8};
	  vector <int> sticks(sticks_, sticks_+sizeof(sticks_)/sizeof(*sticks_)); 
	int C = 1; 
	int K = 3; 
	double _ = 4.0; 
END
CASE(3)
	int sticks_[] = {1000000000, 1000000000, 1};
	  vector <int> sticks(sticks_, sticks_+sizeof(sticks_)/sizeof(*sticks_)); 
	int C = 2; 
	int K = 5; 
	double _ = 1.0; 
END
CASE(4)
	int sticks_[] = {76, 594, 17, 6984, 26, 57, 9, 876, 5816, 73, 969, 527, 49};
	  vector <int> sticks(sticks_, sticks_+sizeof(sticks_)/sizeof(*sticks_)); 
	int C = 789; 
	int K = 456; 
	double _ = 34.92; 
END

}
// END CUT HERE