Artifact Content
Not logged in

Artifact fecf6da132539bbed45173dae1257b4d115dbc86


#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>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class FoxAndBusiness { public:
	double minimumCost(int K, int totalWork, vector <int> a, vector <int> p)
	{
		double L=0, R=1e+60;
		for(int _=0; _<10000; ++_)
		{
			double C = (L+R)/2;
			(possible(C, K, a, p) ? R : L) = C;
		}
		return R * totalWork;
	}

	bool possible(double C, int K, const vector<int>& a, const vector<int>& p)
	{
		vector<double> v;
		for(int i=0; i<a.size(); ++i)
			v.push_back( (C-p[i])*a[i] );
		sort(v.rbegin(), v.rend());
		double r = accumulate(v.begin(), v.begin()+K, 0.0);
		return 3600*double(K) <= r;
	}
};

// 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) {
 bool ok = (abs(Expected - Received) < 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(_, FoxAndBusiness().minimumCost(K, totalWork, a, p));}
int main(){

CASE(0)
	int K = 1; 
	int totalWork = 10; 
	int a_[] = {10};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int p_[] = {20};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	double _ = 3800.0; 
END
CASE(1)
	int K = 1; 
	int totalWork = 100; 
	int a_[] = {50, 60};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int p_[] = {1000, 2000};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	double _ = 107200.0; 
END
CASE(2)
	int K = 2; 
	int totalWork = 300; 
	int a_[] = {10, 20, 47};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int p_[] = {15, 20, 98765};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	double _ = 77500.0; 
END
CASE(3)
	int K = 4; 
	int totalWork = 1000; 
	int a_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int p_[] = {20, 30, 40, 58, 60, 70, 80, 90, 100, 150};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	double _ = 531764.705882353; 
END
CASE(4)
	int K = 25; 
	int totalWork = 100000; 
	int a_[] = {17016,47415,83045,39455,34491,97616,91719,95101,85384,68562,36351,24654,36129,18257,87966,10190,67335,56121,20172,16228,16294,69902,83879,76475,81100,55688,5409,16764,33750,98625,56617,76728,50765,48650,58685,85248,46583,22525,8200,32280,59445,3381,85440,51313,26000,21507,39766,61104,76355,92950};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int p_[] = {59966,49102,35349,70206,65668,60145,10705,28056,9582,11619,8537,42449,30488,14162,1272,9064,817,15046,99637,16513,94277,42777,28196,34907,20309,47607,41378,33097,36974,74425,46978,13157,15027,12723,66607,26639,59698,37250,28554,78762,19543,55908,47550,42978,74731,4218,69250,16558,66512,12939};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	double _ = -1; 
END
CASE(5)
	int K = 1; 
	int totalWork = 100000; 
	int a_[] = {1};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
    int p_[] = {100000};
	  vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); 
	double _ = -1; 
END
}
// END CUT HERE