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. 走近RDD

    RDD(Resilient Distributed Datasets)弹性分布式数据集.RDD可以看成是一个简单的"数组",对其进行操作也只需要调用有限的"数组" ...

  2. ORACLE SEQUENCE的简单介绍

    先假设有这么一个表: create table S_Depart ( DepartId INT not null, DepartName NVARCHAR2() not null, DepartOrd ...

  3. px,em,rem,vw单位在网页和移动端的应用

    px: 是网页设计中最常用的单位,然而1px到底是多大长,恐怕没有人能回答上来 它用来表示屏幕设备物理上能显示的最小的一个点,这个点不是固定宽度的,不同设备上点的长度.比例有可能会不同. 假设:你现在 ...

  4. docker在CentOS7下部署指南

    docker只支持CentOS7.x系统,所以近期根据docker官网指南自己搭建了一套,供大家参考. 1.部署Centos7.x系统,查看系统版本. 2.执行 sudo yum update 更新到 ...

  5. shell脚本编程基础

       最近学习了shell脚本编程,感觉自己的脚本写的不太好,所以想把shell脚本相关的知识系统的整理一下,便于以后的学习和使用. 一.shell脚本基础    shell脚本是利用shell的功能 ...

  6. 二,ESP8266 GPIO和SPI和定时器和串口

    让这个灯亮 我们写lua用这个软件 链接:http://pan.baidu.com/s/1kVN09cr 密码:pfv7 http://www.cnblogs.com/yangfengwu/p/624 ...

  7. mybaties-plus入门

    目前正在维护的公司的一个项目是一个ssm架构的java项目,dao层的接口有大量数据库查询的方法,一个条件变化就要对应一个方法,再加上一些通用的curd方法,对应一张表的dao层方法有时候多达近20个 ...

  8. 201521123002 《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰,内容覆盖 ...

  9. 201521123113 《Java程序设计》第1周学习总结

    1. 本章学习总结 1.java是一个面向对象的编程语言,相对于c++来说代码较简便又好用.第一次接触java时感觉每句代码比较难写,但学习了一些快捷方法后就很方便了. 2.java运行于JVM,因此 ...

  10. 关于学习Python的一些心得

    1.关注函数参数的类型,如列表,字符串,int,而不是关注函数的功能 2.导入模块numpy,dir(numpy) 查看所有属性 3.''.join(列表)  将列表拆成字符串