Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool tickets(const std::vector<int>& customers) {
- int fifties = 0, tf = 0; //tf = twentyfives
- for (int bill : customers) {
- if (bill == 25) { tf++; } //need 0 change
- else if (bill == 50) {
- if (--tf < 0) return false; //needs 25 change
- fifties++;
- }
- else { //bill == 100, needs (50+25) OR (25*3) change
- if (fifties > 0 && tf > 0) { fifties--; tf--; }
- else if ((tf -= 3) < 0) { return false; }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement