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个挨在一起的位置很复杂,所以考虑先把所有4个位置挨在一起的座位干掉。

  当存在某个队还没被安排的人数大于等于4,那么就扔一个这样的座位给他们,如果不存在这样的座位,那就分配一个两个座的座位。如果分配出了问题,直接输出NO吧。

  然后考虑剩余人数为3的队伍,要么安排4座,要么安排1个两座剩1人(余下来的一人等会儿考虑,并加入暂时无法安排的人)。

  此时,所有队伍剩余人数不超过2人。

  继续考虑剩余人数为2的队伍,如果存在4座,那么旁边就会多出可以坐1人的座位,否则就安排坐2座,如果没有2座,就把暂时无法安排的人数加2。

  最后所有剩下的座位显然都是要1个人1个人地坐了,所以计算一下,判断还可以坐的人数是否大于等于暂时无法安排的人数。

Code

 /**
* Codeforces
* Problem#839B
* Accepted
* Time: 15ms
* Memory: 2100k
*/
#include <bits/stdc++.h>
using namespace std; int n, k;
int rest[], cnt[]; inline void init() {
scanf("%d%d", &n, &k);
rest[] = n << , rest[] = n;
for(int i = , x; i <= k; i++) {
scanf("%d", &x);
while(x > ) {
if(rest[])
rest[]--, x -= ;
else if(rest[])
rest[]--, x -= ;
else {
puts("NO");
exit();
}
}
if(x)
cnt[x]++;
}
} inline void solve() {
while(cnt[]--) {
if(rest[])
rest[]--, rest[]++;
else if(rest[])
rest[]--;
else
cnt[] += ;
}
puts((rest[] * + rest[] + rest[] >= cnt[]) ? ("YES") : ("NO"));
} int main() {
init();
solve();
return ;
}

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

  1. CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)

    血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 ...

  2. Codeforces 839B - Game of the Rows

    839B - Game of the Rows 思路:先放4个的,然后再放2个的,最后再放1个的. 代码: #include<bits/stdc++.h> using namespace ...

  3. Codeforces 839B Game of the Rows【贪心】

    B. Game of the Rows time limit per test:1 second memory limit per test:256 megabytes input:standard ...

  4. Codeforces 437C The Child and Toy(贪心)

    题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...

  5. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心

    C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...

  8. Codeforces Testing Round #12 B. Restaurant 贪心

    B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...

  9. Codeforces 437D The Child and Zoo(贪心+并查集)

    题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路 ...

随机推荐

  1. 有关于异常捕获点滴,plus我也揭揭java的短

    ▄︻┻┳═一『异常捕获系列』Agenda: ▄︻┻┳═一有关于异常捕获点滴,plus我也揭揭java的短 ▄︻┻┳═一根据异常自定义处理逻辑([附]java异常处理规范) ▄︻┻┳═一利用自定义异常来 ...

  2. 使用dynamic引发的异常:无法对 null 引用执行运行时绑定

    今天上午运营反映有商户的账单没有生成. 查看日志,在批量生成账单服务执行过程中,因为如下异常而中断了: 跑批异常 Microsoft.CSharp.RuntimeBinder.RuntimeBinde ...

  3. sqoop往远程hdfs写入数据时出现Permission denied 的问题

    猜测出现该问题的原因是sqoop工具用的是执行sqoop工具所用的本地用户名. 如果远程hdfs用的用户是hdfs,那么我本地还需要建一个名为hdfs的用户? 其实不需要,只要为用户增加一个环境变量就 ...

  4. Debug常用命令

    R命令 查看.修改CPU中寄存器的值 -r ;查看寄存器的值 -r cs ;修改cs寄存器的值 D命令 查看内存中的内容 ;d 段地址:偏移地址 -d 1000:01 ;查看内存100001处的内容 ...

  5. 事件响应模型(游戏引擎、JAVA中等应用)

    事件,我们在生活中时时在产生事件并且做出响应,如早晨出门时,看见外面下雨了,这时候我们需要带把伞等情况! 在现实生活之中事件分为人为事件和自然事件,那么在计算机操作系统中也不例外,存在两种事件 1.人 ...

  6. python random函数

    .random模块方法说明 random.random()函数是这个模块中最常用的方法了,它会生成一个随机的浮点数,范围是在0.0~1.0之间. random.uniform()正好弥补了上面函数的不 ...

  7. Python全栈-数据库介绍与基本操作

    .数据库管理软件的由来 数据库的产生是为了解决数据的永久储存.数据安全.以及对方对外服务时能够实现并发服务等效果.例如解决前面所学的Scoket编程中,在不考虑硬件问题的基础上,服务端服务多个客户端时 ...

  8. Discuz!代码大全

    1.[ u]文字:在文字的位置可以任意加入您需要的字符,显示为下划线效果. 2.[ align=center]文字:在文字的位置可以任意加入您需要的字符,center位置center表示居中,left ...

  9. 重建二叉树POJ2255

    重建二叉树 给定一棵二叉树的前序遍历和中序遍历的结果,求其后序遍历. 输入输入可能有多组,以EOF结束.每组输入包含两个字符串,分别为树的前序遍历和中序遍历.每个字符串中只包含大写字母且互不重复.输出 ...

  10. 【转】LoadRunner压力测试:测试报告结果分析

    见:https://blog.csdn.net/haoui123/article/details/62036723