Advertisement
ulfben

Jerry & The Gilmore Girls

Sep 12th, 2016
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. bool tickets(const std::vector<int>& customers) {
  2.     int fifties = 0, tf = 0; //tf = twentyfives
  3.     for (int bill : customers) {       
  4.         if (bill == 25) { tf++; } //need 0 change
  5.         else if (bill == 50) {
  6.             if (--tf < 0) return false; //needs 25 change
  7.             fifties++;
  8.         }
  9.         else { //bill == 100, needs (50+25) OR (25*3) change
  10.             if (fifties > 0 && tf > 0) { fifties--; tf--; }
  11.             else if ((tf -= 3) < 0) { return false; }
  12.         }      
  13.     }
  14.     return true;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement