English · Original
Chinese · Translation
Formal · Original
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}.
<center> A row in the airplane</center>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 _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_.
## 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.
[samples]
## Note
In the first sample, Daenerys can place the soldiers like in the figure below:
<center></center>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).
丹妮莉丝·坦格利安有一支由 #cf_span[k] 个士兵群体组成的军队,第 #cf_span[i] 个群体包含 #cf_span[ai] 名士兵。她希望将她的军队带到海的另一边以获取铁王座。她最近购买了一架飞机来运送军队穿越海洋。这架飞机有 #cf_span[n] 行,每行有 #cf_span[8] 个座位。我们称两个座位为相邻座位,如果它们在同一行且位于座位对 #cf_span[{1, 2}]、#cf_span[{3, 4}]、#cf_span[{4, 5}]、#cf_span[{5, 6}] 或 #cf_span[{7, 8}] 中。
丹妮莉丝·坦格利安希望将她的军队安排在飞机上,使得来自不同群体的两名士兵不会坐在相邻的座位上。
你的任务是确定是否存在一种安排方式,使得上述条件得以满足。
第一行包含两个整数 #cf_span[n] 和 #cf_span[k] (#cf_span[1 ≤ n ≤ 10000], #cf_span[1 ≤ k ≤ 100]) —— 分别表示行数和士兵群体的数量。
第二行包含 #cf_span[k] 个整数 #cf_span[a1, a2, a3, ..., ak] (#cf_span[1 ≤ ai ≤ 10000]),其中 #cf_span[ai] 表示第 #cf_span[i] 个群体的士兵数量。
保证 #cf_span[a1 + a2 + ... + ak ≤ 8·n]。
如果我们能将士兵安排在飞机上,请输出 "_YES_"(不含引号);否则输出 "_NO_"(不含引号)。
你可以任意选择每个字母的大小写。
在第一个样例中,丹妮莉丝可以像下图那样安排士兵:
在第二个样例中,由于第二组的士兵总会与第一组的士兵坐在相邻座位上,因此无法安排士兵。
在第三个样例中,丹妮莉丝可以将第一组安排在座位 #cf_span[(1, 2, 7, 8)],第二组安排在其余所有座位上。
在第四个样例中,她可以将前两个组分别安排在座位 #cf_span[(1, 2)] 和 #cf_span[(7, 8)],第三组安排在座位 #cf_span[(3)],第四组安排在座位 #cf_span[(5, 6)]。
## Input
第一行包含两个整数 #cf_span[n] 和 #cf_span[k] (#cf_span[1 ≤ n ≤ 10000], #cf_span[1 ≤ k ≤ 100]) —— 分别表示行数和士兵群体的数量。第二行包含 #cf_span[k] 个整数 #cf_span[a1, a2, a3, ..., ak] (#cf_span[1 ≤ ai ≤ 10000]),其中 #cf_span[ai] 表示第 #cf_span[i] 个群体的士兵数量。保证 #cf_span[a1 + a2 + ... + ak ≤ 8·n]。
## Output
如果我们能将士兵安排在飞机上,请输出 "_YES_"(不含引号);否则输出 "_NO_"(不含引号)。你可以任意选择每个字母的大小写。
[samples]
## Note
在第一个样例中,丹妮莉丝可以像下图那样安排士兵: 在第二个样例中,由于第二组的士兵总会与第一组的士兵坐在相邻座位上,因此无法安排士兵。在第三个样例中,丹妮莉丝可以将第一组安排在座位 #cf_span[(1, 2, 7, 8)],第二组安排在其余所有座位上。在第四个样例中,她可以将前两个组分别安排在座位 #cf_span[(1, 2)] 和 #cf_span[(7, 8)],第三组安排在座位 #cf_span[(3)],第四组安排在座位 #cf_span[(5, 6)]。
**Definitions**
Let $ n \in \mathbb{Z}^+ $ be the number of rows in the airplane.
Let $ k \in \mathbb{Z}^+ $ be the number of soldier groups.
Let $ A = (a_1, a_2, \dots, a_k) $ be a sequence of positive integers, where $ a_i $ is the size of the $ i $-th group.
Each row has 8 seats, indexed as follows:
- Seat pairs: $ \{1,2\}, \{3,4\}, \{4,5\}, \{5,6\}, \{7,8\} $ are *neighboring* (adjacent).
- Thus, neighboring seat pairs define the following *adjacency constraints*:
- Seats 1–2, 2–1 are neighbors
- Seats 3–4, 4–3, 4–5, 5–4, 5–6, 6–5 are neighbors
- Seats 7–8, 8–7 are neighbors
- Two seats are *non-neighboring* if they are not connected by the above adjacency.
A valid seating assigns soldiers to seats such that:
- Each soldier occupies exactly one seat.
- No two soldiers from *different* groups occupy neighboring seats.
- Soldiers from the *same* group may occupy neighboring seats.
Total seats: $ 8n $.
Total soldiers: $ \sum_{i=1}^k a_i \leq 8n $ (guaranteed).
**Constraints**
1. $ 1 \leq n \leq 10000 $
2. $ 1 \leq k \leq 100 $
3. $ 1 \leq a_i \leq 10000 $ for all $ i \in \{1, \dots, k\} $
4. $ \sum_{i=1}^k a_i \leq 8n $
**Objective**
Determine whether there exists an assignment of the $ a_i $ soldiers from each group $ i $ to the $ 8n $ seats such that no two soldiers from *different* groups occupy neighboring seats.
**Output**
- "YES" if such an assignment exists.
- "NO" otherwise.
API Response (JSON)
{
"problem": {
"name": "B. Game of the Rows",
"description": {
"content": "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 ha",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 1000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF839B"
},
"statements": [
{
"statement_type": "Markdown",
"content": "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 ha...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "丹妮莉丝·坦格利安有一支由 #cf_span[k] 个士兵群体组成的军队,第 #cf_span[i] 个群体包含 #cf_span[ai] 名士兵。她希望将她的军队带到海的另一边以获取铁王座。她最近购买了一架飞机来运送军队穿越海洋。这架飞机有 #cf_span[n] 行,每行有 #cf_span[8] 个座位。我们称两个座位为相邻座位,如果它们在同一行且位于座位对 #cf_span[{1, 2}]...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "**Definitions** \nLet $ n \\in \\mathbb{Z}^+ $ be the number of rows in the airplane. \nLet $ k \\in \\mathbb{Z}^+ $ be the number of soldier groups. \nLet $ A = (a_1, a_2, \\dots, a_k) $ be a sequence of ...",
"is_translate": false,
"language": "Formal"
}
]
}