Question:- Logan owns an waffle shop in earth named sweetpluse. There are only three types of coins in earth: Rs. 5, Rs. 10 and Rs. 15. An waffle costs Rs. 5.
There are N people (numbered 1 through N) standing in a queue to buy waffle from sweetpluse. Each person wants to buy exactly one waffle. For each valid i, the i-th person has one coin with value ai. It is only possible for someone to buy a waffle when logan can give them back their change exactly ― for example, if someone pays with a Rs. 10 coin, logan needs to have a Rs. 5 coin that he gives to this person as change.
Initially, logan has no money. He wants to know if he can sell waffle to everyone in the queue, in the given order.
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.(optional)
The first line of each test case contains a single integer N. The second line contains N space-separated integers a1,a2,…,aN.
For each test case, print a single line containing the string "YES" if all people can be served or "NO" otherwise (without quotes).
Constraint:-ai∈{5,10,15} for each valid i
Example Input 3 2 5 10 2 10 5 2 5 15 Example Output YES NO NO
Explanation Example case 1: The first person pays with a Rs. 5 coin. The second person pays with a Rs. 10 coin and logan gives them back the Rs. 5 coin (which he got from the first person) as change.
Example case 2: The first person already cannot buy a waffle because logan cannot give them back Rs. 5.
Example case 3: The first person pays with a Rs. 5 coin. The second person cannot buy the waffle because logan has only one Rs. 5 coin, but he needs to give a total of Rs. 10 back as change.
Solve this question using c++ programming language
Aucun commentaire:
Enregistrer un commentaire