Advertisement
Guest User

Untitled

a guest
Feb 19th, 2021
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function solve(input) {
  2. let kozunaci = Number(input[0]);
  3. let index = 1;
  4. let sugar = 0;
  5. let flour = 0;
  6. let maxFlour = 0;
  7. let maxSugar = 0;
  8. let sugarNeeded = 0;
  9. let flourNeeded = 0;
  10.  
  11.  
  12. for (let i = 1; i <= kozunaci; i++) {
  13.  
  14. let sugarQuantity = Number(input[index++]);
  15. let flourQuantity = Number(input[index++]);
  16.  
  17. sugar += sugarQuantity;
  18. flour += flourQuantity;
  19.  
  20. if (sugarQuantity > maxSugar) {
  21. maxSugar = sugarQuantity;
  22. }
  23.  
  24. if (flourQuantity > maxFlour) {
  25. maxFlour = flourQuantity;
  26. }
  27.  
  28. }
  29.  
  30. sugarNeeded = Math.ceil(sugar / 950.0);
  31.  
  32. flourNeeded = Math.ceil(flour / 750.0);
  33.  
  34. console.log(`Sugar: ${sugarNeeded}`);
  35. console.log(`Flour: ${flourNeeded}`);
  36. console.log(`Max used flour is ${maxFlour} grams, max used sugar is ${maxSugar} grams.`);
  37.  
  38. }
  39.  
  40. solve(['3', '400', '350', '250', '300', '450', '380', '']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement