B. Game of the Rows

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 n rows, 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).

题目链接:http://codeforces.com/contest/839/problem/B

分析:贪心可做,具体看代码(有空补上题解)

 #include<cstdio>
#include<algorithm>
using namespace std;
int n,m,c[],i,j,x,a[];
int main(){
scanf("%d%d",&n,&m);
c[]=n*;
c[]=n;
for(i=;i<=m;i++)scanf("%d",&x),a[x]++;
for(i=;i;i--)while(a[i]--){
for(j=;j;j--)if(c[j]){
c[j]--;
int t=min(i,j);
a[i-t]++;
if(j-t->)c[j-t-]++;
break;
}
if(!j){
puts("NO");
return ;
}
}
puts("YES");
}

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

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

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

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

  3. Codeforces 839B - Game of the Rows

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

  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. Android活动生命周期

    任务(Task) Android 是使用任务(Task)来管理活动的,一个任务就是一组存放在栈里的活动的集合,这个栈也被称作返回栈(Back Stack).在默认情况下,每当我们启动了一个新的活动,它 ...

  2. Solr集群搭建详细教程(二)

    注:欢迎大家转载,非商业用途请在醒目位置注明本文链接和作者名dijia478,商业用途请联系本人dijia478@163.com. 之前步骤:Solr集群搭建详细教程(一) 三.solr集群搭建 注意 ...

  3. VR、AR、MR定义区别

    近日, 获得谷歌5亿美元融资的技术公司Magic Leap在WSJD展会中放出了一段实录视频,引起不小骚动.如今,也有媒体称他们为MR公司,那么VR.AR.MR之间到底有什么区别呢. VR.AR.MR ...

  4. Kotlin——最详细的常量、变量、注释的使用

    在Kotlin中的变量.常量以及注释多多少少和Java语言是有着不同之处的.不管是变量.常量的定义方式,还是注释的使用.下面详细的介绍Kotlin中的变量.常量.注释的使用.以及和Java的对比. 如 ...

  5. [置顶] Xamarin android如何调用百度地图入门示例(一)

    在Xamarin android如何调用百度地图呢? 首先我们要区分清楚,百度地图这是一个广泛的概念,很多刚刚接触这个名词"百度地图api",的确是泛泛而谈,我们来看一下百度地图的 ...

  6. bzoj 4824: [Cqoi2017]老C的键盘

    Description 老 C 是个程序员.     作为一个优秀的程序员,老 C 拥有一个别具一格的键盘,据说这样可以大幅提升写程序的速度,还能让写出来的程序 在某种神奇力量的驱使之下跑得非常快.小 ...

  7. js 自定义html标签属性

    <input type="text" id="txtBox" displayName="123456" /> 获取自定义属性值: ...

  8. 串口调试者v2.1------开源c#串口调试工具

    第一步:上图 第二步:上代码 >>>>>>>>>>>源代码下载<<<<<<<<< ...

  9. NestedScrollingParent, NestedScrollingChild 详解

    之前听同事提起过 NestedScrollingView,但是一直没有时间去了解,最近一段时间比较空,才开始去了解.先点开,看 NestedScrollingView 源码: public class ...

  10. [Spark内核] 第38课:BlockManager架构原理、运行流程图和源码解密

    本课主题 BlockManager 运行實例 BlockManager 原理流程图 BlockManager 源码解析 引言 BlockManager 是管理整个Spark运行时的数据读写的,当然也包 ...