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 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

Copy
4
25 25 50 50
output

Copy
YES
input

Copy
2
25 100
output

Copy
NO
input

Copy
4
50 50 25 25
output

Copy
NO

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int n,a[];
cin>>n;
for(int i=;i<n;i++)
{
cin>>a[i];
}
int t1=,t2=,flag=;
for(int i=;i<n;i++)
{
if(a[i]==)
{
t1++;
continue;
}
if(a[i]==)
{
if(t1>=)
{
t2++;
t1--;
continue;
}
else
{
flag=;
break;
}
}
if(a[i]==)
{
if(t1>=&&t2>=)
{
t1--;
t2--;
continue;
}
if(t1>=)
{
t1=t1-;
continue;
} else
{
flag=;
break;
}
} }
if(flag==)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return ;
}

A. Cinema Line的更多相关文章

  1. codeforces A. Cinema Line 解题报告

    题目链接:http://codeforces.com/problemset/problem/349/A 题目意思:题目不难理解,从一开始什么钱都没有的情况下,要向每一个人售票,每张票价格是25卢布,这 ...

  2. Codeforces Round #202 (Div. 2) A,B

    A. Cinema Line time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  3. http://codeforces.com/contest/349

    A. Cinema Line time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. ACM团队周赛题解(1)

    这次周赛题目拉了CF315和CF349两套题. 因为我代码模板较长,便只放出关键代码部分 #define ll long long #define MMT(s,a) memset(s, a, size ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. Codeforces #380 div2 C(729C) Road to Cinema

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. cf380D Sereja and Cinema 组合数学

              time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  9. ZOJ 3635 Cinema in Akiba(线段树)

    Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is ful ...

随机推荐

  1. 一篇docker的详细技术文章

    http://www.open-open.com/lib/view/open1423703640748.html

  2. html 5 data-* (dataset) 属性和 jquery data方法比较

    一些文章在介绍html 5 data-* (dataset)属性时,会提到jquery的data方法,认为data方法能够很好的利用html 5的这个特性.但实际上,二者的兼容性是很差的.下面给出一段 ...

  3. Paxos在大型系统中的应用场景

    https://timyang.net/distributed/paxos-scenarios/ 在分布式算法领域,有位非常重要的短发叫Paxos,它的重要性有多高呢?Google的Chubby[1] ...

  4. 巧用 git rebase 合并多个 commit。

    一.为什么需要合并多个 commit 呢?   有时候,我们开发一个功能. 修修补补 commit 了很多次,过多的 commit 会显得很复杂. 不够直观,不能比较清晰查看那些 commit 是对应 ...

  5. 《Head First Servlets & JSP》-2-概述

    什么是容器 Servlet没有main()方法,他们受控于另一个Java应用,这个java应用称为容器(Container). Web服务器应用(如Apache)得到一个指向Servlet的请求(如何 ...

  6. C#实现类只实例化一次(被多个类访问调用)

    C#简单写法如下: public class Singleton {     private static Singleton _instance = null;     private Single ...

  7. C#内存映射大文件并使用Marshal解析结构体信息

    内存映射数据处理类主要函数及变量如下: string _filepath; /// <summary> /// 引用内存映射文件 /// </summary> private ...

  8. 禁用GridView控件前5行记录

    禁用GridView控件前5行记录. 应该在GridView控件写OnRowDataBound事件: 如果你只想禁用删除铵钮的话: 网页运行效果: 如果你想把整行禁用的话,可以这样写: 运行效果: 禁 ...

  9. 记一次RSA非对称算法的排坑经历

    Map<String,Object> encryParam = new HashMap<>(5); encryParam.put("connectorUrl" ...

  10. seleniumIDE是Firefox的录制功能使用

    selenium第二课(脚本录制seleniumIDE的使用) 转自:https://www.cnblogs.com/hustar0102/p/5906958.html 一.Selenium也具有录制 ...