1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <bits/stdc++.h> #define all(vec) vec.begin(),vec.end() #define lson(o) (o<<1) #define rson(o) (o<<1|1) #define SZ(a) ((long long) a.size()) #define debug(var) cerr << #var <<":"<<var<<"\n"; #define cend cerr<<"\n-----------\n" #define fsp(x) fixed<<setprecision(x)
using namespace std;
using ll = long long; using ull = unsigned long long; using DB = double;
using CD = complex<double>;
static constexpr ll MAXN = (ll)1e6+10, INF = (1ll<<61)-1; static constexpr ll mod = 998244353; static constexpr double eps = 1e-8; const double pi = acos(-1.0);
ll lT,testcase;
void Solve() { ll N,a_fresh,b_tired,x_do,y_rest; cin >> N>>a_fresh>>b_tired>>x_do>>y_rest; ll l=N*b_tired,r=N*a_fresh; ll ans=0; do { ll num_a=min(x_do,N),num_b=N-num_a; ll lans=num_a*a_fresh+num_b*b_tired; ans=max(lans,ans); }while (false); do { ll num_a=N/(x_do+y_rest),rem=N-num_a*(x_do+y_rest); ll lans=num_a*x_do*a_fresh+min(rem,x_do)*a_fresh+ (rem-min(rem,x_do))*b_tired; ans=max(lans,ans); }while (false); do { ll num_a=N/(x_do+y_rest); ll rem=0; if (num_a>=1) { rem=N-num_a*(x_do+y_rest); rem+=y_rest; }else { rem=N-num_a*(x_do+y_rest); } ll lans=num_a*x_do*a_fresh+rem*b_tired; ans=max(lans,ans); }while (false); cout<<ans<<"\n"; }
signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef LOCAL cout.setf(ios::unitbuf); #endif
cin >> lT; for (testcase=1;testcase<=lT;++testcase) Solve(); return 0; }
|