Artifact Content
Not logged in

Artifact 4948478ca41a65d0b27c89bc978b0a28fe5f9e11


#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 WaterTank { public:
	double minOutputRate(vector <int> t, vector <int> x, int C)
	{
		double L=0, R=1000000; // (L,R]
		for(int _=0; _<10000; ++_) {
			double mid = (L+R)/2;
			(can(t, x, C, mid) ? R : L) = mid;
		}
		return R;
	}

	bool can(const vector<int>& t, const vector<int>& x, int C, double R)
	{
		double v = 0;
		for(int i=0; i<t.size(); ++i) {
			v = max(0.0, v+(x[i]-R)*t[i]);
			if(v > C)
				return false;
		}
		return true;
	}
};

// 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(_, WaterTank().minOutputRate(t, x, C));}
int main(){

CASE(0)
	int t_[] = {3,3};
	  vector <int> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int x_[] = {1,2};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int C = 3; 
	double _ = 0.9999999999999999; 
END
CASE(1)
	int t_[] = {1,2,3,4,5};
	  vector <int> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int x_[] = {5,4,3,2,1};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int C = 10; 
	double _ = 1.9999999999999996; 
END
CASE(2)
	int t_[] = {5949,3198,376,3592,4019,3481,5609,3840,6092,4059};
	  vector <int> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int x_[] = {29,38,96,84,10,2,39,27,76,94};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int C = 1000000000; 
	double _ = 0.0; 
END
CASE(3)
	int t_[] = {9,3,4,8,1,2,5,7,6};
	  vector <int> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int x_[] = {123,456,789,1011,1213,1415,1617,1819,2021};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int C = 11; 
	double _ = 2019.1666666666665; 
END
CASE(4)
	int t_[] = {100};
	  vector <int> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int x_[] = {1000};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int C = 12345; 
	double _ = 876.55; 
END
/*
CASE(5)
	int t_[] = ;
	  vector <int> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int x_[] = ;
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int C = ; 
	double _ = ; 
END
CASE(6)
	int t_[] = ;
	  vector <int> t(t_, t_+sizeof(t_)/sizeof(*t_)); 
	int x_[] = ;
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int C = ; 
	double _ = ; 
END
*/
}
// END CUT HERE