ulfben

Jerry & The Gilmore Girls

Sep 12th, 2016
129
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×