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
  1. 2 2
    5 8
output
  1. YES
input
  1. 1 2
    7 1
output
  1. NO
input
  1. 1 2
    4 4
output
  1. YES
input
  1. 1 4
    2 2 1 2
output
  1. 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

  1. /**
  2. * Codeforces
  3. * Problem#839B
  4. * Accepted
  5. * Time: 15ms
  6. * Memory: 2100k
  7. */
  8. #include <bits/stdc++.h>
  9. using namespace std;
  10.  
  11. int n, k;
  12. int rest[], cnt[];
  13.  
  14. inline void init() {
  15. scanf("%d%d", &n, &k);
  16. rest[] = n << , rest[] = n;
  17. for(int i = , x; i <= k; i++) {
  18. scanf("%d", &x);
  19. while(x > ) {
  20. if(rest[])
  21. rest[]--, x -= ;
  22. else if(rest[])
  23. rest[]--, x -= ;
  24. else {
  25. puts("NO");
  26. exit();
  27. }
  28. }
  29. if(x)
  30. cnt[x]++;
  31. }
  32. }
  33.  
  34. inline void solve() {
  35. while(cnt[]--) {
  36. if(rest[])
  37. rest[]--, rest[]++;
  38. else if(rest[])
  39. rest[]--;
  40. else
  41. cnt[] += ;
  42. }
  43. puts((rest[] * + rest[] + rest[] >= cnt[]) ? ("YES") : ("NO"));
  44. }
  45.  
  46. int main() {
  47. init();
  48. solve();
  49. return ;
  50. }

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. Batch normalization批标准化的理解

    BN的基本思想,其提出是解决梯度消失的问题的某一方法. 在深度神经网络做非线性变换前的激活输入值(x=wu+b,u是输入),当层数越深的时候,输入值的分布就会发生偏移,梯度出现消失的情况, 一般是整体 ...

  2. javaIO流

    File类(File类的概述和构造方法) A:File类的概述 File更应该叫做一个路径 文件路径或者文件夹路径 路径分为绝对路径和相对路径 绝对路径是一个固定的路径,从盘符开始 相对路径相对于某个 ...

  3. div上下左右居中方法

    方法一:在浏览器中只有一个div的情况 { position:fixed; position:fixed; ; ; ; ; margin:auto; } 方法一 方法二:一个父元素div和一个已知宽度 ...

  4. 关于hibernate一级缓冲和二级缓冲

    关于一级缓冲和二级缓冲的内容,在面试的时候被问起来了,回答的不是很满意,所以有专门找了些有关这方面的文章加以理解 出自:http://blog.csdn.net/zdp072/article/deta ...

  5. [13]Windows 内核情景分析 --- 网络通信

    典型的基于tcpip协议套接字方式的网络通信模块层次: 应用程序 socket api WS2_32.dll socket irp Afd.sys tdi irp Tcpip.sys 回调函数接口 各 ...

  6. python 将word另存为txt

      import os import os.path from win32com import client as wc c=[] rootdir=["d:/77"] #以该路径为 ...

  7. pycharm python3.5 神奇的导入问题

    说明:pycharm目录中没有同名.py文件,则可以直接用import util导入: 若有同名.py文件,则导入的时候需要加入所在文件夹名称

  8. Spring源码阅读(八)

    摘要: 本文首先将举例说明如何使用BeanWrapper,然后根据例子中的结果分析BeanWrapper的源码.由于在spring中BeanWrapperImpl是BeanWrapper接口的唯一实现 ...

  9. java中的神奇"this"

    java中的神奇"this",神奇的原因事它能不用new就可以直接创造一个对象出来,后来研究发现,其实java的“this”使用时,也是"new"了一个当前的对 ...

  10. python模板字符串和格式化字符串

    模板字符串:用string模块里的Template Template()里面把字符串中某个值用设置变量${key}的方式先写好,然后在substitute()的方式把变量用其他值代替,就完成了字符串的 ...