Minimum Amount of Time to Fill Cups Solution in C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nBrute Force\n# Complexi
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nBrute Force\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n^2logn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n    int fillCups(vector<int>& amount) {\n        int time=0;\n        while(true)\n        {\n            sort(amount.begin(), amount.end());\n            if(amount[2]>0)\n            {\n                amount[2]--;\n                time++;\n            }\n            if(amount[1]>0)\n            {\n                amount[1]--;\n            }\n            else if(amount[2]==0)\n            {\n                break;\n            }\n        }\n        return time;\n    }\n};\n```\n# Approach\n<!-- Describe your approach to solving the problem. -->\nOptimized Approach\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n    int fillCups(vector<int>& amount) {\n        int time=0;\n        time = max(*max_element(amount.begin(), amount.end()), (accumulate(amount.begin(), amount.end(), 0)+1)/2);\n        return time;\n    }\n};\n```\n![upvote new.jpg](https://assets.leetcode.com/users/images/2b5ba58f-c507-452d-a47d-f722b6c7403b_1682612638.84197.jpeg)\n
['C++']