CF839B.Game of the Rows
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains a__i 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.
丹妮莉丝·坦格利安拥有一支由 k 组士兵组成的军队,其中第 i 组包含 ai 名士兵。她希望将这支军队运送到海峡对岸以夺取铁王座。最近,她购买了一架飞机来运送她的军队穿越海峡。这架飞机共有 n 排座位,每排有 8 个座位。我们称两个座位为相邻座位,当且仅当它们位于同一排,且属于以下座位对之一:{1,2}、{3,4}、{4,5}、{5,6} 或 {7,8}。
飞机中的一排座位
丹妮莉丝·坦格利安希望将她的军队安排在飞机上,使得来自不同组的任意两名士兵都不坐在相邻座位上。
你的任务是判断:是否存在一种安排方式,使得上述条件得以满足。
输入格式
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 _a_1, _a_2, _a_3, ..., a__k (1 ≤ a__i ≤ 10000), where a__i denotes the number of soldiers in the i-th group.
It is guaranteed that _a_1 + _a_2 + ... + a__k ≤ 8·n.
第一行包含两个整数 n 和 k(1 ≤ n ≤ 10000,1 ≤ k ≤ 100),分别表示行数和士兵组数。
第二行包含 k 个整数 a1,a2,a3,...,ak(1 ≤ ai ≤ 10000),其中 ai 表示第 i 组的士兵人数。
保证 a1 + a2 + ... + ak ≤ 8⋅n。
输出格式
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.
如果可以将士兵安排在飞机上,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。
每个字母的大小写可任意选择。
输入输出样例
输入#1
2 2 5 8
输出#1
YES
输入#2
1 2 7 1
输出#2
NO
输入#3
1 2 4 4
输出#3
YES
输入#4
1 4 2 2 1 2
输出#4
YES
说明/提示
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).
在第一个样例中,丹妮莉丝可以如下图所示安排士兵:

在第二个样例中,无法在平面上安排士兵,因为第二组的士兵总会坐在与第一组某位士兵相邻的座位上。
在第三个样例中,丹妮莉丝可将第一组士兵安排在座位 (1, 2, 7, 8) 上,第二组士兵安排在其余所有座位上。
在第四个样例中,她可将前两组士兵分别安排在座位 (1, 2) 和 (7, 8) 上,第三组安排在座位 (3) 上,第四组安排在座位 (5, 6) 上。
输入解题思路,AI测评打分。不知道怎么写?