JiamingBlogger

2016年1月16日 星期六

Vasya - Clerk

Description

The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollars bill. A "Avengers" ticket costs 25 dollars.
Vasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.
Can Vasya sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
Return YES, if Vasya can sell a ticket to each person and give the change. Otherwise return NO.

Solution

from operator import add
def tickets(people):
    deposit = [0,0,0]
    for p in people:
        if p == 25:
            deposit = map(add, deposit, [1,0,0])
        elif p == 50:
            deposit = map(add, deposit, [-1,1,0])
        else:
            if deposit[0] >=1 and deposit[1] >=1:
               deposit = map(add, deposit, [-1,-1,0])
            elif deposit[1] == 0 and deposit[0] >=3:
               deposit = map(add, deposit, [-3, 0, 0])
            else:
               deposit = map(add, deposit, [-3, 0, 0])
        if deposit[0] < 0 or deposit[1] < 0 or deposit[2] < 0: return 'NO'
    return 'YES'



張貼者: Unknown 於 清晨5:12
以電子郵件傳送這篇文章BlogThis!分享至 X分享至 Facebook分享到 Pinterest
標籤: codewars, python

沒有留言:

張貼留言

較新的文章 較舊的文章 首頁
訂閱: 張貼留言 (Atom)

關於我自己

Unknown
檢視我的完整簡介

網誌存檔

  • ▼  2016 (8)
    • ▼  1月 (8)
      • Customize the FileInputFormat to Read Whole File
      • Vasya - Clerk
      • Storage: Configure Disks, Partitions and Disk Moun...
      • Spark Laoding Data From S3
      • Using Maven to build Spark Job in Scala
      • Triangle Type
      • How many consecutive numbers are needed?
      • Is it a eight bit signed number?
簡單主題. 技術提供:Blogger.