最近太zz了,老是忘记带脑子。。。
补的以前的cf,发现脑子不好使。。。
 
 
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has nrows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.

A row in the airplane

Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.

Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.

Input

The first line contains two integers n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 100) — the number of rows and the number of groups of soldiers, respectively.

The second line contains k integers a1, a2, a3, ..., ak (1 ≤ ai ≤ 10000), where ai denotes the number of soldiers in the i-th group.

It is guaranteed that a1 + a2 + ... + ak ≤ 8·n.

Output

If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes).

You can choose the case (lower or upper) for each letter arbitrary.

Examples
input
2 2
5 8
output
YES
input
1 2
7 1
output
NO
input
1 2
4 4
output
YES
input
1 4
2 2 1 2
output
YES
Note

In the first sample, Daenerys can place the soldiers like in the figure below:

In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group.

In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats.

In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).

题意:主要的就是不同的军队不能挨着坐。

所以能把4个位置坐满的话就先坐满,然后考虑2个位置的。

对于4个人来说就是坐在中间的4个位置,对于3个人来说也是坐在中间,但是可以有一种操作,把3个人分成2个人和1个人,

然后是考虑2个人和1个人的,都是坐在两边的位置或者中间坐一个2个人坐一个1个人,或者中间坐2个1个人的。

最近太zz了,一开始想的太麻烦了,忘记了还有比较大小这种操作了。。。

代码:

 #include<bits/stdc++.h>
using namespace std;
int a[];
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
for(int i=;i<k;i++)
scanf("%d",&a[i]);
int sum1=n;
int sum2=*n;
for(int i=;i<k;i++){
int d=min(sum1,a[i]/);
sum1-=d;
a[i]-=d*;
}
sum2+=sum1;
for(int i=;i<k;i++){
int d=min(sum2,a[i]/);
sum2-=d;
a[i]-=d*;
}
int tmp=sum2+sum1;
for(int i=;i<k;i++)
tmp-=a[i];
if(tmp>=)printf("YES\n");
else printf("NO\n");
}
return ;
}

Codeforces 839 B. Game of the Rows-贪心的更多相关文章

  1. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  2. Codeforces 839B Game of the Rows - 贪心

    Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldie ...

  3. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  4. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  5. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  6. Educational Codeforces Round 7 E. Ants in Leaves 贪心

    E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connec ...

  7. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  8. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  9. codeforces Gym 100187F F - Doomsday 区间覆盖贪心

    F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...

  10. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

随机推荐

  1. MyEclipse - 问题集 - Workspace in use or cannot be created, choose a different one(转)

    转:http://wsfly.iteye.com/blog/1044986 eclipse 使用一段时间后,有时会因为一些故障自己就莫名奇妙的关闭了,再打开时有时没有问题,有时有会提示错误 Works ...

  2. 自动化测试(二)如何用python写一个用户登陆功能

    需求信息: 写一个判断登录的程序: 输入: username password 最大错误次数是3次,输入3次都没有登录成功,提示错误次数达到上限 需要判断输入是否为空,什么也不输入,输入一个空格.n个 ...

  3. eclipse集成python(Pydev插件安装)

    1.下载PyDev的压缩包,解压后会有features和plugins两个文件夹,将两个文件夹的内容拷贝到eclipse对应的文件夹中,重新启动eclipse 2.配置python 2.1打开ecli ...

  4. Python全栈工程师(每周总结:3)

     ParisGabriel                                                           每天坚持 一天一篇 点个订阅吧  灰常感谢    当个死 ...

  5. 课时34:丰富的else语句以及简洁的with语句

    目录: 一.丰富的else语句 二.简洁的with语句 三.课时34课后习题及答案 *********************** 一.丰富的else语句 ********************** ...

  6. webpack 基础

    1.安装: npm install --save-dev webpack         npm install --save-dev webpack@<version> 如果是webpa ...

  7. intellij idea 2017 快捷键(提高工作效率)

    1.Shift+Enter Annotation annotation = c.getAnnotation(A.class); 这个时候你写代码的时候可能光标在c.getAnno中的某一个位置,那么你 ...

  8. 第十一篇:MySQL基础

    本篇内容 MySQL概述 MySQL安装 MySQL库增.删.改.查 MySQL表增.删.改.查 MySQL表记录增.删.改.查 一. MySQL概述 MySQL是一个关系型数据库管理系统,由瑞典 M ...

  9. Spring2集成iBatis2

    从数据库中查询一条记录,演示Spring与iBatis的集成 1 编写sqlmaps与Domain对象 <?xml version="1.0" encoding=" ...

  10. 电阻 (resistance)

    电阻 (resistance) 题目描述 每次小x物理作业没做完时,总是会去和老师交流感情,他们之间由此建立起来良好的师生关系.于是有一天,老师带着一道物理难题来见小x. 这道题给出了一个有n个电阻的 ...