Advertisement
Zinak

Untitled

Aug 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,b,p,f,h,c,d,e;
  6.     cin>>n;
  7.     while(n--)
  8.     {
  9.         cin>>b>>p>>f;
  10.         cin>>h>>c;
  11.         d=(p*2)+(f*2);
  12.         if(b>=d)
  13.            cout<<(p*h)+(f*c)<<endl;
  14.            else{
  15.            e=b/2;
  16.            if(h>c){
  17.                if(p<=e && f<=(e-p))
  18.            cout<<(p*h)+((f*c))<<endl;
  19.            else if (p<=e && f>(e-p))
  20.             cout<<(p*h)+((e-p)*c);
  21.             else if(p>e)
  22.                 cout<<(p*h)<<endl;
  23.            }
  24.            else if(c>h){
  25.                if(f<=e && p<=(e-f))
  26.            cout<<(p*h)+((f*c))<<endl;
  27.            else if (f<=e && p>(e-f))
  28.             cout<<((e-f)*h)+(f*c);
  29.             else if(f>e)
  30.                 cout<<(f*c)<<endl;
  31.            }
  32.            }
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement