Using Heap js solution
\n/**\n * @param {number[]} amount\n * @return {number}\n */\nvar fillCups = function (amount) {\n  const q = new MaxPriorityQueue();\n  for (let i = 0; i < amo
```\n/**\n * @param {number[]} amount\n * @return {number}\n */\nvar fillCups = function (amount) {\n  const q = new MaxPriorityQueue();\n  for (let i = 0; i < amount.length; i++) {\n    q.enqueue(amount[i]);\n  }\n\n  let total = 0;\n  while (true) {\n    let a = q.dequeue().element;\n    let b = q.dequeue().element;\n\n    if (a == 0 || b == 0) {\n      total = total + (a + b);\n          return total;\n    } else {\n      total++;\n      a--;\n      b--;\n\n      q.enqueue(a);\n      q.enqueue(b);\n    }\n  }\n};\n\n```
['Heap (Priority Queue)', 'JavaScript']