#include using namespace std; #define ll long long #define ull unsigned long long #define REP(i, n) for(int i=0;i> Tf >> Vf >> Hf >> Td >> Vd >> Hd; double t1 = Tf + sqrt(2*(Hf-Hd)); double t2 = Td + (((Tf-Td)*Vf) / (Vf - Vd)); if(Vf == Vd && Tf == Td) { t2 = 0; } double t3 = Tf + sqrt(2*Hf); //cout << "t3: " << t3 << endl; double Td_up = sqrt((2.0/3)*Hd); double Vd_up = Hd/Td_up; double b = Tf-Vd_up-3*Td; double c = Hf-(1/2)*Tf*Tf+Vd_up*Td+(3.0/2)*Td*Td; double tm = (-b+sqrt(b*b-4*c))/2; //cout << "tm: " << tm << endl; double t; if(t1 > t2) { t = t1; } else if(t3 < t2) { t = t3; } else { t = t2; } //if(t < tm) t = tm; //cout << "t: " << t << endl; double s = ((t-Tf)*Vf); //cout << "s: " << s << endl; double t_run = t + (s/Vd); if(t == t3) { t_run = Td + 2*(s/Vd); } cout << t_run << endl; }