A. Cinema Line
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 equals25, 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

简介:买电影票一张25一张,然后营业员最初没有钱,给你一个只有25 ,50,100的数列,问能否成功卖票,成功输出“yes”否则输出“NO”

题解:直接模拟,x代表25的票数y代表50的票数z代表100的票数

代码如下:

 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=1e5+;
int a[maxn];
int x,y,z,n;
int main()
{
scanf("%d",&n);
int flag=true;
x=y=z=;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
if(flag)
{
if(a[i]==)
{
x++;
}
else if(a[i]==)
{
y++;
if(x>=)
{
x--;
}
else
{
flag=false;
}
}
else
{
z++;
if(y>=&&x>=)
{
y--;
x--;
}
else if(x>=)
{
x=x-;
}
else
{
flag=false;
}
} } }
if(flag)
{
cout<<"YES\n";
}
else
{
cout<<"NO\n";
}
}

题目连接http://codeforces.com/contest/349/problem/A

http://codeforces.com/contest/349的更多相关文章

  1. codeforces 725D . Contest Balloons(贪心+优先队列)

    题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...

  2. codeforces.com/contest/325/problem/B

    http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...

  3. CodeForces - 725D Contest Balloons 贪心

              D. Contest Balloons          time limit per test 3 seconds         memory limit per test 2 ...

  4. http://codeforces.com/contest/555/problem/B

    比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的... 比赛后用set pair过了... #include <bits/stdc++.h&g ...

  5. http://codeforces.com/contest/845

    A. Chess Tourney time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. http://codeforces.com/contest/610/problem/D

    D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. http://codeforces.com/contest/612/problem/D

    D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  8. http://codeforces.com/contest/536/problem/B

    B. Tavas and Malekas time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. http://codeforces.com/contest/535/problem/C

    C. Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. MVC分页示例

    分页说明 对于大多数非枚举数据,我们都需要进行分页管理.在WEBFORM时代,有GridView,也可以配合AspNetPager很方便的实现分页,到了MVC,也同样可以使用MVCPager,作者都是 ...

  2. ADO.NET中SQL Server数据库连接池

    连接到数据库服务器通常由几个需要很长时间的步骤组成. 必须建立物理通道(例如套接字或命名管道),必须与服务器进行初次握手,必须分析连接字符串信息,必须由服务器对连接进行身份验证,必须运行检查以便在当前 ...

  3. docker学习之--日常命令

    .查看镜像 sudo docker images sudo pull docker.io #下载镜像 sudo push docker.io #上传镜像 sudo docker save -o cen ...

  4. Java IO包装流如何关闭

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt381 问题: (1)JAVA的IO流使用了装饰模式,关闭最外面的流的时候会自 ...

  5. windows 下 Mutex和Critical Section 区别和使用

    Mutex和Critical Section都是主要用于限制多线程(Multithread)对全局或共享的变量.对象或内存空间的访问.下面是其主要的异同点(不同的地方用黑色表示). Mutex Cri ...

  6. java四则运算生成器

    题目描述: 从<构建之法>第一章的 "程序" 例子出发,像阿超那样,花二十分钟写一个能自动生成小学四则运算题目的命令行 "软件",满足以下需求: 除 ...

  7. JAVA课设---五子棋

    1.团队博客链接 JAVA课设-五子棋-团队博客 2.个人负责模块: ①对鼠标事件的处理 , 此模块需处理五子棋的放置问题.颜色转换问题.以及当五子连线时弹出窗口显示结果. ②对MainFrame中主 ...

  8. 201521123099 《Java程序设计》 第10周学习总结

    1. 本周学习总结 2. 书面作业 本次PTA作业题集异常.多线程 finally 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中finally中捕获异常需要注意什么? final ...

  9. 让SAE下的wordpress支持文件上传

    非PHP程序员照着源码打的小布丁… SAE是不允许本地磁盘读写的,所以使用wordpress撰写文章的时候, 上传控件默认是用不了的,幸好SAE提供了storage服务来存储文件,那就可以修改word ...

  10. Linux SDK之uClinux、Broadcom、Atheros、Realtek、Ralink、Marvell、Intel

    接触的Linux SDK越来越多,整理整理,分享分享,不求系统全面,对您有帮助便足矣 文中大部分是与AP/Router SoC解决方案(单芯片WIFI 路由器解决方案)相关的Linux SDK SDK ...