Codeforces Round #376 (Div. 2) B. Coupons and Discounts

来源:互联网 发布:美国反智主义 知乎 编辑:程序博客网 时间:2024/05/17 10:57
B. Coupons and Discounts
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

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 a1a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.

Output

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

Examples
input
41 2 1 2
output
YES
input
31 0 1
output
NO
Note

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.

题意:就是他只有两种买披萨的方式,一种一天买两个,一种连续两天每天买一个,一天可以用多种方式,问可不可以用这两种方式买到所需要的披萨。

思路:首先当我们遇到奇数是我们肯定要用第二种方式,然后让其减一成为偶数,偶数就可以用第第一种方式。到最后全为偶数就证明可以买到所需的披萨。我本来想的是先用第二种买买到不能买,然后再看能不能被第二种买,如果不能就输出NO,所以用我的程序运行3 2 3结果就是NO,但是正确答案是YES,晚上想了好久,WA了好几遍,早上来了换了一种思路一遍就过了,所以当一种思路要是老是错的时候就可以换种思路想一想。

代码:

#include<stdio.h>#include<cstring>#include<iostream>#include<algorithm>#include<math.h>#include<stdlib.h>#include<stack>#include<vector>#include<string.h>#include<map>#define INF 0x3f3f3f3f3fusing namespace std;int a[200002];int main(){    int n;    while(~scanf("%d",&n))    {        for(int i=0;i<n;i++)        {            scanf("%d",&a[i]);        }        for(int i=0;i<n-1;i++)        {            if(a[i]%2==1)            {                a[i]-=1;                a[i+1]-=1;            }        }        int flag=1;        for(int i=0;i<n;i++)        {            a[i]%=2;            if(a[i]!=0)            {                flag=0;            }        }        if(flag==0)        {            printf("NO\n");        }        else        {            printf("YES\n");        }    }}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 脑子里兴奋的头疼怎么办 吃什么药 一个月宝宝异常兴奋不睡觉怎么办 四个月宝宝晚上兴奋不睡觉怎么办 20个月宝宝半夜惊醒哭闹怎么办 小孩吃了氨茶碱兴奋不睡觉怎么办 孩子在学校被同学撞鼻骨折怎么办 孩子在学校无意致使同学受伤怎么办 9个月的宝宝吃坏东西腹泻怎么办 8个月发烧到38度怎么办 1岁半宝宝鼻塞发烧38度6怎么办 八个月的宝宝发热38度怎么办 八个月宝宝发热在38度怎么办 8个月孩子发烧38度怎么办 6个月孩子发烧38度多怎么办 7个月孩子发烧38度怎么办 小明上课总是东张西望你该怎么办 初中二年级贪玩游戏说不听怎么办 孩子上课经常和别的同学说话怎么办 小孩五年级了上课坐不住怎么办 孩子老是纠结小事抓不住重点怎么办 没文化不懂教不了孩孑怎么办 孩孑学习不好老师不让上课怎么办 5个月婴儿睡得少怎么办 教育案例——幼儿爱打小报告怎么办 上班的时候同事老是爱插话怎么办 孕晚期右侧卧睡觉宝宝好动怎么办 乐扣玻璃碗盖子长霉怎么办 乐扣保鲜盒密封圈有异味怎么办 8个月的宝宝不吃饭怎么办 宝宝十一个月了不爱吃饭怎么办 一岁八个月宝宝不爱吃饭怎么办 14个月的宝宝不爱吃饭怎么办 宝宝一岁多又黑又瘦又小该怎么办? 15个月宝宝偏瘦该怎么办 早期肺癌手术后身体瘦该怎么办 4个月婴儿的眼里有触摸糊怎么办 七个月宝宝断奶不喝奶粉怎么办 2个月的宝宝抓头怎么办 4岁宝宝吃东西一点都不认真怎么办 猫吐了白色黏液或泡沫怎么办 六个月的宝宝拉肚子老不好怎么办