Simulation and Formula
Simulation\nWe pick two largest piles, and fill two cups (or one, if we have only one pile left).\n\nC++\ncpp\nint fillCups(vector<int>& a) {\n    int res = 0;\
#### Simulation\nWe pick two largest piles, and fill two cups (or one, if we have only one pile left).\n\n**C++**\n```cpp\nint fillCups(vector<int>& a) {\n    int res = 0;\n    for (; max({a[0], a[1], a[2]}) > 0; ++res) {\n        sort(begin(a), end(a));\n        --a[2];\n        --a[1];\n    }\n    return res;\n}\n```\n#### Formula\nIf we have one pile much larger than the others, the number of seconds will be the same as the number of cups in that large pile.\n\nOr, if piles are of similar size, and we can always fill two cups, we will need `(a[0] + a[1] + a[2] + 1) / 2` seconds (we do `+ 1` in case the sum of cups is odd).\n\n**C++**\n```cpp\nint fillCups(vector<int>& a) {\n    return max({a[0], a[1], a[2], (a[0] + a[1] + a[2] + 1) / 2});\n}\n```
['C']