fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int t; scanf("%d",&t);
  6.  
  7. while(t--)
  8. {
  9. int b,p,f,h,c;
  10. int ans = 0;
  11.  
  12. scanf("%d %d %d",&b,&p,&f);
  13. scanf("%d %d",&h,&c);
  14.  
  15. if(h<c)
  16. {
  17. //swap h and c
  18. int tmp = c;
  19. c = h;
  20. h = tmp;
  21.  
  22. //swap p and f
  23. tmp = p;
  24. p = f;
  25. f = tmp;
  26.  
  27. }
  28.  
  29. // h >= c
  30.  
  31. if(p*2 < b) //age patty sesh hoye jabe, ruti baki thakbe
  32. {
  33. //p ta burger hobe
  34. ans += p*h; //p*h taka bikri korte parbo
  35.  
  36. b -= p*2; //p ta burger er jonno p*2 ta ruti khoroch hobe
  37. }
  38. else //age ruti sesh hobe
  39. {
  40. // (b/2) ta burger hobe
  41.  
  42. ans += (b/2)*h; //(b/2)*h taka bikri korte parbo
  43.  
  44. b -= (b/2) * 2; //b/2 ta burger er jonno (b/2)*2 ta ruti khoroch hobe
  45. }
  46.  
  47. //baki jotogula c type er burger banano jay
  48.  
  49. //same logic
  50.  
  51. if(f*2 < b)
  52. {
  53. //f ta burger
  54. ans += f*c;
  55.  
  56. //ruti baki thakleo kaje lagbe na, tai ignore updating b
  57. }
  58. else
  59. {
  60. //b/2 ta burger hobe
  61. ans += (b/2)*c;
  62. }
  63.  
  64.  
  65. printf("%d\n",ans);
  66.  
  67.  
  68. }
  69.  
  70.  
  71.  
  72.  
  73. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
0