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. spring整合web项目演示

  2. floyd路径记录

    #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #in ...

  3. interface 接口 和多态的含义

    <?php //interface关键字用于定义接口 interface ICanEat{ //接口里面的方法不需要方法的实现 public function eat($food) ; } // ...

  4. ubuntu下使用PIL中的show函数,无法显示图片的问题

    问题描述:ubuntu14.04系统,python2.7(version),正在学习python中, from PIL import Image im = Image.open('1.jpg') im ...

  5. Laradock使用教程(新手版)

    Laradock使用教程 背景 最近我们公司把开发环境从windows系统换到了Ubuntu系统.用windows系统的时候,我们一般用phpStudy集成环境的比较多.换到Linux环境下,我们选择 ...

  6. HDU 5373 The shortest problem (数学)

    题意:给定两个数的n和m,有一种操作,把 n 的各位数字加起来放到 n后面形成一个新数n,问重复 m 次所得的数能否整除 11. 析:这个题首先要知道一个规律奇数位的和减去偶数位的和能被11整除的数字 ...

  7. HTML与CSS入门经典(第9版)试读 附随书源码 pdf扫描版​

    HTML与CSS入门经典(第9版)是经典畅销图书<HTML与CSS入门经典>的最新版本,与过去的版本相同,本书采用直观.循序渐进的方法,为读者讲解使用HTML5与CSS3设计.创建并维护世 ...

  8. asp 控件定时器 局部刷新

    <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePan ...

  9. ConnectionState详解

    ConnectionState有六个属性值ConnectionState.Broken;与数据源连接断开.只有在连接打开后才有可能发生这种情况.可以关闭处于这种状态下的连接,然后重新打开.Connec ...

  10. tensorboard的安装及遇到的问题

    1 安装tensorboard 打开anaconda prompt,键入下边的命令: activate tensorflow pip install tensorboard 当执行“activate ...