349A

编程入门 行业动态 更新时间:2024-10-14 10:38:45

349A

349A

A. Cinema Line
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
The new “Die Hard” movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A “Die Hard” ticket costs 25 rubles. Can the booking clerk 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?
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Output
Print “YES” (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print “NO”.
Examples
Input
4
25 25 50 50
Output
YES
Input
2
25 100
Output
NO
Input
4
50 50 25 25
Output
NO
题解:用a,b,c分别记录25,50,100的数量,当顾客钱大于25时,找回的钱减少a/b/c的数量。若其中有一个少于0,便NO。

#include<iostream>
using namespace std;
int main()
{int n,i,j,k,a=1,b=0,c=0;int q[100001];cin>>n;for(i=0;i<n;i++){cin>>q[i];}if(q[0]!=25){cout<<"NO";return 0;}for(i=1;i<n;i++){if(q[i]==25){a++;}else if(q[i]==50){b++;a--;}if(q[i]==100){c++;if(b>0&&a>0){b--;a--;}else{a-=3;}}if(a<0||b<0){cout<<"NO";return 0;}}cout<<"YES";return 0;
}

更多推荐

349A

本文发布于:2024-03-07 09:31:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1717455.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!