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}.
![](https://i-blog.csdnimg.cn/blog_migrate/3d0190a5ef945ad49d6d6c94d4895f27.png)
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.
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.
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.
题意如上所示。
题解:贪心,首先很容易想到对于每组中有4个,肯定占中间最长的即3456,之后处理2,最后处理1。做这种题发现不能乱模拟,必须思路情绪.不然很难1A。
#include <bits/stdc++.h>
using namespace std;
int main()
{
//std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n, k, num;
int four, two, one;
four = two = one = 0;
scanf("%d%d",&n,&k);
for(int i = 1;i <= k;i ++) {
scanf("%d",&num);
four += num / 4, num %= 4;
two += num / 2, num %= 2;
one += num;
}
int Four = n, Two = n * 2, One = 0;
if(four >= Four) four -= Four, Four = 0;
else Four -= four, four = 0;
if(four > 0) two += four * 2, four = 0;
else Two += Four, One += Four, Four = 0;
if(two > 0) {
if(Two >= two) Two -= two, two = 0;
else two -= Two, Two = 0;
if(Two > 0) One += Two, Two = 0;
} else {
One += Two, Two = 0;
}
puts(One >= 2 * two + one ? "YES" : "NO");
return 0;
}