Coupons and Discounts
1 second
256 megabytes
standard input
standard output
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition.
Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day.
There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total).
As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days.
Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n.
The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.
If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes).
4
1 2 1 2
YES
3
1 0 1
NO
In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.
In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days.
分析:贪心,模拟;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fLL
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<ll,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,a[maxn];
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n)scanf("%d",&a[i]);
rep(i,,n)
{
if(a[i]&)
{
if(a[i+])a[i+]--;
else return *puts("NO");
}
}
puts("YES");
//system("Pause");
return ;
}
Coupons and Discounts的更多相关文章
- Codeforces 376B. Coupons and Discounts
B. Coupons and Discounts time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces 731B Coupons and Discounts(贪心)
题目链接 Coupons and Discounts 逐步贪心即可. 若当前位为奇数则当前位的下一位减一,否则不动. #include <bits/stdc++.h> using name ...
- 【50.49%】【codeforces 731B】Coupons and Discounts
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- CodeForces 731B Coupons and Discounts (水题模拟)
题意:有n个队参加CCPC,然后有两种优惠方式,一种是一天买再次,一种是买两天,现在让你判断能不能找到一种方式,使得优惠不剩余. 析:直接模拟,如果本次是奇数,那么就得用第二种,作一个标记,再去计算下 ...
- Codeforces Round #376 (Div. 2) A B C 水 模拟 并查集
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 【Codeforces】Round #376 (Div. 2)
http://codeforces.com/contest/731 不发题面了,自己点链接 总结一下 考场上 原以为这次要加很多raiting... 但FST狗记邓,只加了58rating 总结一下 ...
- codeforces754D Fedor and coupons
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- codeforces 754D. Fedor and coupons
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- CF 161B Discounts(贪心)
题目链接: 传送门 Discounts time limit per test:3 second memory limit per test:256 megabytes Description ...
随机推荐
- Java 集合 fail-fast机制 [ 转载 ]
Java 集合 fail-fast机制 [转载] @author chenssy 摘要:fail-fast产生原因.解决办法 在JDK的Collection中我们时常会看到类似于这样的话: 例如,Ar ...
- hdu_2328_Corporate Identity(暴力枚举子串+KMP)
题目链接:hdu_2328_Corporate Identity 题意: 给你n个串,让你找这n个串的最大公共子串 题解: 串比较小,暴力枚举第一个的子串,然后KMP判断是否可行 #include&l ...
- C语言实现用户输入
用户输入一个字符串然后回车表示结束.因为用户在输入的过程中长度是不确定的,所以要求自己使用的循环写的更好.在这里自己写了一个代码,效率不高,相对来说如果能模拟出C++中的vector向量可能会好一些. ...
- PerformSelector 和 NSInvocation
- 一步一步学EF系列2【最简单的一个实例】
整个文章我都会用最简单,最容易让人理解的方式给大家分享和共同学习.(由于live Writer不靠谱 又得补发一篇) 一.安装 Install-Package EntityFramework 二.简单 ...
- DSO分类及应用
1.DSO的分类,标准DSO(生成主数据标识.对于相同关键字段的值进行合并.可直接出具报表).写优化的DSO(不生成主数据标识.不合并相同关键字段的值.速度快可用于存储大容量数据).直接写入的DSO, ...
- java读写串口
http://blog.csdn.net/xxyy888/article/details/8946046
- 2015 Multi-University Training Contest 3
1001 Magician 线段树.根据奇偶性分成4个区间.维护子列和最大值. 想法很简单.但是并不好写. 首先初始化的时候对于不存在的点要写成-INF. 然后pushup的时候.对于每个区间要考虑四 ...
- LibRTMP优化之调整输出块大小
1. 为什么要调整输出块大小 首先在RTMP_Connect0函数中LibRTMP是关闭了Nagle算法这个TCP选项的,为了实时性这样做是好的,但是要注意到LibRTMP的结构体RTMP的成员是有m ...
- MySQL Administrator的简单操作
A.创建数据库 1.运行MySQL Administrator服务器,如下图. 2.点击"Catalogs",下面出现已有的数据库,右击已有的数据库,选择“Create New S ...