A. Cinema Line
2 seconds
256 megabytes
standard input
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?
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.
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
4
25 25 50 50
YES
2
25 100
NO
4
50 50 25 25
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的更多相关文章
- codeforces A. Cinema Line 解题报告
题目链接:http://codeforces.com/problemset/problem/349/A 题目意思:题目不难理解,从一开始什么钱都没有的情况下,要向每一个人售票,每张票价格是25卢布,这 ...
- 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 ...
- http://codeforces.com/contest/349
A. Cinema Line time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- ACM团队周赛题解(1)
这次周赛题目拉了CF315和CF349两套题. 因为我代码模板较长,便只放出关键代码部分 #define ll long long #define MMT(s,a) memset(s, a, size ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 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 ...
- 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 ...
- cf380D Sereja and Cinema 组合数学
time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- ZOJ 3635 Cinema in Akiba(线段树)
Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is ful ...
随机推荐
- 封装 Toast
一. ToastView.java 1 import android.content.Context; import android.view.LayoutInflater; import andro ...
- php5.6,curl上传的变化
$ch = curl_init ();curl_setopt ( $ch, CURLOPT_SAFE_UPLOAD, false); //php5.6要加上这个 $fields = array(); ...
- 关于c#分支语句和分支嵌套还有变量的作用域。
分支语句: if....else if....else 必须以 if 开头 后面加括号写入需要判断的内容. 举个栗子说明一下 if (bool类型(比较表达式)) // 他会判断括号内的条件是否 ...
- java中字符串处理、串联和转换的几个常用方法,以及如果需要自己编程实现的具体实施步骤。
What? 如何分类? 如何使用? //String 类提供处理 Unicode 代码点(即字符)(TT观点:指的莫非就是对象的意思.)和 Unicode 代码单元(即 char 值)的方法.(TT观 ...
- python 删除正在for循环遍历的list正确做法
先放一个python遍历发生的异常: ls =[1,2,3,4,5,6,7,8,9] for i in ls: print("i",i) print("ls", ...
- Inheritance with EF Code First: Part 2 – Table per Type (TPT)
In the previous blog post you saw that there are three different approaches to representing an inher ...
- jQuery选择器和选取方法.RP
我们已经使用了带有简单Css选择器的jQuery选取函数:$().现在是时候深入了解jQuery选择器语法,以及一些提取和扩充选中元素集的方法了. 一.jQuery选择器 在CSS3选择器标淮草案定义 ...
- IIC协议解释
IIC协议解释 (1)概述 I2C(Inter-Integrated Circuit BUS) 集成电路总线,该总线由NXP(原PHILIPS)公司设计,多用于主控制器和从器件间的主从通信,在小数据量 ...
- Algorithms - Insertion sort
印象 图1 插入排序过程 思想 插入排序(Insertion Sort)的主要思想是不断地将待排序的元素插入到有序序列中,是有序序列不断地扩大,直至所有元素都被插入到有序序列中. 分析 时间复杂度: ...
- 微信开放平台 redirect_uri参数错误
微信开放平台 redirect_uri参数错误 请注意是开放平台开放平台,公众平台和开放平台不是同一个. 解决办法 在写 授权回调域 时,地址只用写到域名级,不能写到域名下一级,这和QQ互联的回调 ...