Newcoder 128 E.托米歷險記(水~)
阿新 • • 發佈:2018-12-14
Description
這天,托米家的電影院門口排起了長隊–因為最新的電影"托米歷險記"就要上映了! 每個人都有且僅有一張面值為或或元的鈔票.一張電影票的價格是元. 托米想知道售票員能否在初始金錢為並且按排隊順序售票的情況下完成找零.
Input
第一行一個數字,表示排隊的人的數量. 第二行個數字,第個數字為,表示隊伍中第個人所持有的鈔票的面值.
Output
如果售票員能完成找零,輸出(不含引號). 反之輸出.
Sample Input
4 25 25 50 50
Sample Output
4 50 50 25 25
Solution
簡單題,對於的只能找零,對於的優先找零,否則找零
Code
#include<cstdio> using namespace std; int main() { int n,a,b,flag; scanf("%d",&n); a=0,b=0,flag=1; while(n--) { int x; scanf("%d",&x); if(x==25)a++; else if(x==50) { if(a)a--,b++; else flag=0; } else { if(b&&a||a>=3) { if(b&&a)a--,b--; else a-=3; } else flag=0; } } printf("%s\n",flag?"YES":"NO"); return 0; }