#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using lint = long long; using pint = pair; using plint = pair; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; } template bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; } const std::vector> grid_dxs{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); } template T1 floor_div(T1 num, T2 den) { return (num > 0 ? num / den : -((-num + den - 1) / den)); } template std::pair operator+(const std::pair &l, const std::pair &r) { return std::make_pair(l.first + r.first, l.second + r.second); } template std::pair operator-(const std::pair &l, const std::pair &r) { return std::make_pair(l.first - r.first, l.second - r.second); } template std::vector sort_unique(std::vector vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } template int arglb(const std::vector &v, const T &x) { return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x)); } template int argub(const std::vector &v, const T &x) { return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x)); } template IStream &operator>>(IStream &is, std::vector &vec) { for (auto &v : vec) is >> v; return is; } template OStream &operator<<(OStream &os, const std::vector &vec); template OStream &operator<<(OStream &os, const std::array &arr); template OStream &operator<<(OStream &os, const std::unordered_set &vec); template OStream &operator<<(OStream &os, const pair &pa); template OStream &operator<<(OStream &os, const std::deque &vec); template OStream &operator<<(OStream &os, const std::set &vec); template OStream &operator<<(OStream &os, const std::multiset &vec); template OStream &operator<<(OStream &os, const std::unordered_multiset &vec); template OStream &operator<<(OStream &os, const std::pair &pa); template OStream &operator<<(OStream &os, const std::map &mp); template OStream &operator<<(OStream &os, const std::unordered_map &mp); template OStream &operator<<(OStream &os, const std::tuple &tpl); template OStream &operator<<(OStream &os, const std::vector &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; } template OStream &operator<<(OStream &os, const std::array &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; } template std::istream &operator>>(std::istream &is, std::tuple &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; } template OStream &operator<<(OStream &os, const std::tuple &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; } template OStream &operator<<(OStream &os, const std::unordered_set &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template OStream &operator<<(OStream &os, const std::deque &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; } template OStream &operator<<(OStream &os, const std::set &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template OStream &operator<<(OStream &os, const std::multiset &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template OStream &operator<<(OStream &os, const std::unordered_multiset &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template OStream &operator<<(OStream &os, const std::pair &pa) { return os << '(' << pa.first << ',' << pa.second << ')'; } template OStream &operator<<(OStream &os, const std::map &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } template OStream &operator<<(OStream &os, const std::unordered_map &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } #ifdef HITONANODE_LOCAL const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m"; #define dbg(x) std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl #define dbgif(cond, x) ((cond) ? std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl : std::cerr) #else #define dbg(x) ((void)0) #define dbgif(cond, x) ((void)0) #endif // strategy 1 double Calc1(lint N, lint X, lint Y, lint P, lint Q, lint R, lint train) { assert(train <= N); const double prob = 1.0 / (X + Y * train); const lint rem = N - train; return P * train + Q * rem - prob * (R * max(rem - 1, 0LL)); } // strategy 2 double Calc2(lint N, lint X, lint Y, lint P, lint Q, lint R, lint train) { assert(train <= N); const double prob = 1.0 / (X + Y * train); const lint rem = N - train; const double q = 1 - prob; // 1 + q + q^2 + ... + q^(rem - 1) return P * train + Q * (1 - pow(q, rem)) / (1 - q); } // strategy 3 double Calc3(lint N, lint X, lint Y, lint P, lint Q, lint R, lint train) { assert(train <= N); const double prob = 1.0 / (X + Y * train); const lint rem = N - train; const double q = 1 - prob; const double e_per_day = Q - prob * R; if (e_per_day <= 0) { // 1 + q + q^2 + ... + q^(rem - 1) return P * train + Q * (1 - pow(q, rem)) / (1 - q); } else { auto f = [&](lint t) { assert(t <= rem); double e = P * train + e_per_day * (rem - t); if (t) e += Q * (1 - pow(q, t)) / (1 - q); return e; }; lint tlo = 0, thi = rem; auto ftlo = f(tlo), fthi = f(thi); while (thi - tlo > 2) { const lint m1 = (tlo * 2 + thi) / 3; const lint m2 = (tlo + thi * 2) / 3; auto fm1 = f(m1), fm2 = f(m2); if (fm1 > fm2) { thi = m2; fthi = fm2; } else { tlo = m1; ftlo = fm1; } } double best = max(ftlo, fthi); for (lint t = tlo + 1; t < thi; ++t) chmax(best, f(t)); // double last = R / e_per_day; // chmin(last, 1e18); // chmax(last, 0.0); // double best = 0.0; // for (lint l = clamp(roundl(last), 0, rem), t = l - 2; t <= l + 2; ++t) { // if (0 <= t and t <= rem) { // double e = P * train + e_per_day * (rem - t); // e += q * (1 - pow(q, t)) / (1 - q); // chmax(best, e); // } // } return best; } } double Solve(lint N, lint X, lint Y, lint P, lint Q, lint R, auto Calc) { auto eval = [&](lint x) -> double { return Calc(N, X, Y, P, Q, R, x); }; lint lo = 0, hi = N; double elo = eval(0), ehi = eval(N); while (hi - lo > 2) { const lint m1 = (lo * 2 + hi) / 3; const lint m2 = (lo + hi * 2) / 3; auto em1 = eval(m1), em2 = eval(m2); if (em1 > em2) { hi = m2; ehi = em2; } else { lo = m1; elo = em1; } } double ret = max(elo, ehi); for (lint x = lo + 1; x < hi; ++x) chmax(ret, eval(x)); return ret; } int main() { int T; cin >> T; while (T--) { lint N; int X, Y; int P, Q, R; cin >> N >> X >> Y >> P >> Q >> R; // auto ret1 = Solve(N, X, Y, P, Q, R, Calc1); // auto ret2 = Solve(N, X, Y, P, Q, R, Calc2); auto ret3 = Solve(N, X, Y, P, Q, R, Calc3); // dbg(make_tuple(N, ret1, ret2, ret3, Q, R)); // cout << max({ret1, ret2, ret3}) << '\n'; cout << ret3 << '\n'; } }