Simple greedy soln
\n\n# Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n
\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int t=tickets[k];\n\n        int ans=0;\n\n      int n=tickets.size();\n\n      for(int i=0;i<n;i++){\n        if(i<k){\n            if(tickets[i]<=t){\n                ans+=tickets[i];\n            }\n            else{\n               ans+=t; \n            }\n        }\n        else if(i==k)\n        ans+=t;\n        else{\n             if(tickets[i]<t){\n                ans+=tickets[i];\n            }\n            else{\n               ans+=t-1; \n            }\n        }\n      }\n\n        return ans;\n    }\n};\n```
['Greedy', 'Queue', 'C++']