SHARE
TWEET

Jerry & The Gilmore Girls

ulfben Sep 12th, 2016 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
Top