C++ and Python3 || Greedy || Simple and Optimal || 0 ms || Beats 100%
\n# Code\nC++ []\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int ans = 0;\n        for (int i = 0; i < tickets
> ![image.png](https://assets.leetcode.com/users/images/7ce539d1-ed9d-4b2a-bb7a-7b4dbc41dabf_1712660418.2640889.png)\n# Code\n```C++ []\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int ans = 0;\n        for (int i = 0; i < tickets.size(); i++) {\n            if (i > k) ans += min(tickets[i], tickets[k] - 1);\n            else ans += min(tickets[i], tickets[k]);\n        }\n        return ans;\n    }\n};\n```\n```Python3 []\nclass Solution:\n    def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:\n        ans = 0\n        for i in range(len(tickets)):\n            if i > k:\n                ans += min(tickets[i], tickets[k] - 1)\n            else:\n                ans += min(tickets[i], tickets[k])\n        return ans\n```
['Array', 'Greedy', 'C++', 'Python3']