Java solution with explanation
Intuition\nJust keep filling the least and most required cups together\n\n# Approach\nSort the array. Keep removing the smallest value and the largest value by 
# Intuition\nJust keep filling the least and most required cups together\n\n# Approach\nSort the array. Keep removing the smallest value and the largest value by 1, until the smallest one is zero, then increase the answer by the left out max value\n\n# Complexity\n- Time complexity:\nO(smallest value)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    public int fillCups(int[] amount) {\n        Arrays.sort(amount);\n        int ans = 0;\n        int lo=0, hi=2;\n        if(amount[0] == 0) lo++;\n        if(lo==1 && amount[1]==0) return amount[2];\n\n        else if(lo==1){\n            ans += amount[hi];\n            return ans;\n        }\n        while(amount[lo] != 0){\n            ans++;\n            amount[lo]--;\n            amount[hi]--;\n            if(amount[hi-1] > amount[hi]){\n                int temp = amount[hi-1];\n                amount[hi-1] = amount[hi];\n                amount[hi] = temp;\n            }\n        }\n\n        ans += amount[2];\n        return ans;\n    }\n}\n```
['Java']