Codeforces 376B. 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.
/*
ACM训练队要训练n天,第i天有ai个队训练,每个队伍需要一张披萨,教练去买披萨。有两种优惠券第一种是一次买两张,另一种是第一天买一张,
第二天必须买一张。优惠券无限多,问教练能不能用优惠券买全部的披萨,每天买的披萨不会超过需求,且优惠券不能浪费。 贪心:贪心的原则就是尽量不使第二天的数量受影响,就是第一天的能用没两张披萨的优惠圈就用这个,实在不行才用买一张的。
*/
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<map>
#include<set>
#define N 200010
using namespace std;
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
int n,a[N];
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
int f=;
for(int i=;i<n;i++)
{
if(a[i]%)//奇数个
{
if(!a[i+])
{
f=;
break;
}
a[i+]--;
}
}
if(f)
{
puts("NO");
return ;
}
if(a[n]%==)
puts("YES");
else
puts("NO");
return ;
}
Codeforces 376B. Coupons and Discounts的更多相关文章
- Codeforces 731B Coupons and Discounts(贪心)
题目链接 Coupons and Discounts 逐步贪心即可. 若当前位为奇数则当前位的下一位减一,否则不动. #include <bits/stdc++.h> using name ...
- CodeForces 731B Coupons and Discounts (水题模拟)
题意:有n个队参加CCPC,然后有两种优惠方式,一种是一天买再次,一种是买两天,现在让你判断能不能找到一种方式,使得优惠不剩余. 析:直接模拟,如果本次是奇数,那么就得用第二种,作一个标记,再去计算下 ...
- 【50.49%】【codeforces 731B】Coupons and Discounts
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Coupons and Discounts
Coupons and Discounts time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 【Codeforces】Round #376 (Div. 2)
http://codeforces.com/contest/731 不发题面了,自己点链接 总结一下 考场上 原以为这次要加很多raiting... 但FST狗记邓,只加了58rating 总结一下 ...
- 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 754D】Fedor and coupons
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces 754D. Fedor and coupons
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 161 B. Discounts (贪心)
题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...
随机推荐
- LPCTSTR LPCWSTR LPCSTR 含义
#ifdef UNICODE#define LPCTSTR LPCWSTR#else#define LPCTSTR LPCSTR#endif LPCTSTR A 32-bit pointer ...
- asp.net web api 2.2 基础框架(带例子)
链接:https://github.com/solenovex/asp.net-web-api-2.2-starter-template 简介 这个是我自己编写的asp.net web api 2.2 ...
- hadoop配置文件详解,安装及相关操作
一. Hadoop伪分布配置 1. 在conf/hadoop-env.sh文件中增加:export JAVA_HOME=/home/Java/jdk1.6 2. 在conf/core-s ...
- python celery 时区&结果(性能)的坑
本文主要介绍最近使用celery遇到的两个坑.关于时区,以及是否保留结果(celery使用rabbitmq). 先说结论:定时任务记得配置时区:丢弃结果对使用rabbitmq对celery来说,性能提 ...
- Vue中之nextTick函数源码分析
Vue中之nextTick函数源码分析 1. 什么是Vue.nextTick()?官方文档解释如下:在下次DOM更新循环结束之后执行的延迟回调.在修改数据之后立即使用这个方法,获取更新后的DOM. 2 ...
- MyServer
//一.设置一个8089端口的本地IP服务器 1 package myserver; import java.io.IOException; import java.net.ServerSocket; ...
- masonry 设置控件抗压缩及抗拉伸
使用masonry正常设置约束时两个label的显示是下图 添加代码设置蓝色label的抗压缩属性后( [self.missionNameLabel setContentCompressionResi ...
- win10 uwp BadgeLogo 颜色
本文讲的是在上传应用商店出现BadgeLogo颜色问题,和如何解决,因为我是渣渣,本文可能带有一定的主观性和局限性,说的东西可能不对或者不符合每个人的预期.如果觉得我有讲的不对的,就多多包含,或者直接 ...
- 关于限制DHCP服务器广播的另类方法
0. 引言 如图,家里有两台计算机,分别处于不同房间.其中一台PC1能够与光猫直连:另外一台PC2较远,考虑到光猫有WLAN功能,便使用了一个路由器无线桥接到光猫,然后有线连接到PC2(均与光猫处于同 ...
- Java IO(IO流)-1
IO流 第一部分 (outputStream/InputStream Writer/Redaer) IO流对象中输入和输出是相辅相成的,输出什么,就可以输入什么. IO的命名方式为前半部分能干什么,后 ...