Exact Change
Lemonade costs 5. Customers pay with 5, 10 or 20 bills in the given order, and you start with no money. Can you give everyone correct change?
Input: the first line has N; the second line has the N bills in order.
Output: YES or NO.
Constraints:
- 1 ≤ N ≤ 105
- bills are 5, 10 or 20
Sample Tests
Input 1
5 5 5 5 10 20
Output 1
YES
Input 2
3 10 10 10
Output 2
NO
Discussion (opens after you solve — no spoilers before)
No comments yet.