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. Cognos 11.0快速开发指南 Ⅰ

    1. 概述 Cognos Analysics 11,是IBM在Cognos BI 10的版本基础上,吸取业界流行的敏捷BI理念,强化了自助式分析的一款强大BI开发平台工具.其官方文档内容丰富,但是较为 ...

  2. postman 第6节录制case

    我们先安装Postman Interceptor 记得一定要安装Postman Interceptor插件,这样在谷歌浏览器上访问的信息都会在postman的app端同步显示.安装好后Postman ...

  3. 【译】怎样处理 Safari 移动端对图片资源的限制

    原文作者:Thijs van der Vossen 本文翻译自<How to work around the Mobile Safari image resource limit>,原文写 ...

  4. 浏览器控制台console的使用

    前天在团队项目中因为产品需求在提交订单的时候需要多个页面的数据作为提交接口的参数,这种需求让人醉醉的,项目用angular来做的,没办法只能用全局变量来定义要交互的值和localStorage来临时的 ...

  5. poj 3621 二分+spfa

    题意:给出一个有向图,问求一个回路,使得回路上的点权之和/边权之和最大. 这题主要是分析出如何确定ans值.我们将(a1*x1+a2*x2+..+an*xn)/(b1*x1+b2*x2+..+bn*x ...

  6. [置顶] 基于FPGA的VGA简易显存设计&NIOS ii软核接入

    项目简介 本项目基于Altera公司的Cyclone IV型芯片,利用NIOS II软核,2-port RAM与时序控制模块,实现64*48分辨率的显存(再大的显存板载资源m9k不够用) 实现效果如下 ...

  7. 【★】SPF(Dijkstra)算法完美教程

  8. 定时任务之crontab命令

    1.简介 crontab用于设置周期性被执行的命令 Linux系统中Linux调动工作分为两大类: 1.系统执行的工作:系统周期性所要执行的工作,如备份系统数据.清理缓存 2.个人执行的工作:某个用户 ...

  9. 【集美大学1411_助教博客】个人作业2——英语学习APP案例分析 成绩

    个人作业2--英语学习APP案例分析,截止发稿时间全班31人,提交31,未提交0人.有一名同学已经写了作业但忘记提交了,这次给分了,但下不为例.由于助教这周有点忙,所以点评得非常不及时,请同学们见谅. ...

  10. 201521123097 《JAVA程序设计》第七周学习总结

    1. 本周学习总结 总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 源代码: public boolean contains(Object ...