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

题意:飞机有N排,每排八个座位 12  3456   78,要求不同的队伍不能相邻.

题解:

很坑的一道题目,因为考虑到放在中间的也可以放在两边,而放在两边的不一定能放在中间。所以我们先尽量往中间放。

我们考虑将每一个数分解成4,2,1 的形式,然后先把4往中间放,如果中间放不下了就把4拆成两个2。

然后放2,如果放不下了就把2拆成两个1。

最后判断一下有没有放完就可以了。

#include<iostream>
#include<cstdio>
using namespace std;
int n,m,four,two,one,ans1,ans2;
int main()
{
int i,j;
scanf("%d%d",&m,&n);
ans1=m;ans2=m*;
for(i=;i<=n;i++)
{
scanf("%d",&j);
four+=j/;j%=;
two+=j/;j%=;
one+=j;
}
while(four>&&ans1>)ans1--,four--;
two+=four*;four=;
int ans=ans1+ans2;
while(two>&&ans>)ans--,two--;
ans+=ans1;
one+=two*;two=;
while(one>&&ans>)ans--,one--;
if(two||four||one)printf("NO\n");
else printf("YES\n");
return ;
}

B. Game of the Rows的更多相关文章

  1. SQL Server Reporting Services (SSRS): Reporting Services in SQL Server 2012 (codename "Denali") will support XLSX, DOCX formats. Bye bye 65536 rows limit in XLS files ;)

    当SSRS报表的时候,若相应EXCEL是2003以下,在行数超过65536的时候报表会报错 "Microsoft.ReportingServices.ReportProcessing.Han ...

  2. 文本域的宽度和高度应该用cols和rows来控制,还是 用width和height来控制

    文本域宽度如果用cols来控制,缩放网页的时候文本域的宽度不会自动变化 用width来表示就会跟着网页缩放而缩放 看到下面一段文字: 对于内容至上的网页,在禁用CSS的情况下,HTML内容要做到易于阅 ...

  3. Oracle开发之窗口函数 rows between unbounded preceding and current row

    目录=========================================1.窗口函数简介2.窗口函数示例-全统计3.窗口函数进阶-滚动统计(累积/均值)4.窗口函数进阶-根据时间范围统计 ...

  4. Excel: Switch (transpose) columns and rows

    链接:https://support.office.com/en-in/article/Switch-transpose-columns-and-rows-ed1215f5-59af-47e6-953 ...

  5. HTML5 webSQL 中查询结果集 result.rows.item 的用法

    加入查询回调函数如下: function(tx,result){ var len = result.rows.length; var recordset = result.rows.item; ){ ...

  6. SQL Server窗口函数:ROWS与RANGE

    几乎每次我展示SQL Server里的窗口时,人们都非常有兴趣知道,当你定义你的窗口(指定的一组行)时,ROWS与RANGE选项之间的区别.因此在今天的文章里我想给你展示下这些选项的区别,对于你的分析 ...

  7. csharp:Compare two DataTables to rows in one but not the other

    /// <summary> /// 账面数据 Accounting /// </summary> /// <returns></returns> Dat ...

  8. Hive get table rows count batch

    项目中需要比对两种方法计算生成的数据情况,需要做两件事情,比对生成的中间表的行数是否相同,比对最后一张表的数据是否一致. 在获取表的数据量是一条一条地使用select count(*) from ta ...

  9. [转]How to insert a row between two rows in an existing excel with HSSF (Apache POI)

    本文转自:http://stackoverflow.com/questions/5785724/how-to-insert-a-row-between-two-rows-in-an-existing- ...

  10. 第五篇 Integration Services:增量加载-Deleting Rows

    本篇文章是Integration Services系列的第五篇,详细内容请参考原文. 在上一篇你学习了如何将更新从源传送到目标.你同样学习了使用基于集合的更新优化这项功能.回顾增量加载记住,在SSIS ...

随机推荐

  1. BaseAdapter/AsyncTask/..等等细节

    BaseAdapter中的getCount之类的函数,是在constructor之后才启动的.这印证了构造函数的优先级是max的. 图片 这一点的意义在于,当你想给getCount返回一个具体参数的时 ...

  2. Python实现排序算法之快速排序

    Python实现排序算法:快速排序.冒泡排序.插入排序.选择排序.堆排序.归并排序和希尔排序 Python实现快速排序 原理 首先选取任意一个数据(通常选取数组的第一个数)作为关键数据,然后将所有比它 ...

  3. ACM学习历程——HDU5015 233 Matrix(矩阵快速幂)(2014陕西网赛)

    Description In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 2 ...

  4. MySql 扩展存储引擎

    MySql 扩展存储引擎 下面介绍几个列式存储引擎(都有两个版本:社区版.商业版): 一:TokuDB TokuDB 是一个高性能.支持事务处理的 MySQL 和 MariaDB 的存储引擎.Toku ...

  5. hdu 4609 3-idiots —— FFT

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4609 算不合法的比较方便: 枚举最大的边,每种情况算了2次,而全排列算了6次,所以还要乘3: 注意枚举最大 ...

  6. tyvj1015公路乘车——DP

    题目:http://www.joyoi.cn/problem/tyvj-1015 代码如下: #include<iostream> #include<cstdio> using ...

  7. 如何在kindle 3上无法进入 http://www.google.com/reader, 先登陆www.google.com, 然后选择阅读器。

    如何在kindle 3上无法进入 http://www.google.com/reader,  先登陆www.google.com, 然后选择阅读器.

  8. Java虚拟机学习 - 体系结构 内存模型(转载)

    一:Java技术体系模块图 二:JVM内存区域模型 1.方法区 也称"永久代” .“非堆”,  它用于存储虚拟机加载的类信息.常量.静态变量.是各个线程共享的内存区域.默认最小值为16MB, ...

  9. 使用BIND安装智能DNS服务器(三)---添加view和acl配置

    智能DNS的配置主要修改named.conf文件,利用view和acl来实现. acl文件内容,这里只列出一部分,具体详细的可以参考这个网址 纯真IP库,给出了十分详细的IP地址,下载安装后,打开软件 ...

  10. centos6.5安装gmime-2.6

    安装gmime库所需要的依赖库: 1 libffi库安装 简介:glib安装时依赖的库 解压: tar xf libffi-3.0.0.tar.gz 进入目录: cd libffi-3.0.0 安装: ...