最近太zz了,老是忘记带脑子。。。
补的以前的cf,发现脑子不好使。。。
 
 
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 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}.

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

题意:主要的就是不同的军队不能挨着坐。

所以能把4个位置坐满的话就先坐满,然后考虑2个位置的。

对于4个人来说就是坐在中间的4个位置,对于3个人来说也是坐在中间,但是可以有一种操作,把3个人分成2个人和1个人,

然后是考虑2个人和1个人的,都是坐在两边的位置或者中间坐一个2个人坐一个1个人,或者中间坐2个1个人的。

最近太zz了,一开始想的太麻烦了,忘记了还有比较大小这种操作了。。。

代码:

 #include<bits/stdc++.h>
using namespace std;
int a[];
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
for(int i=;i<k;i++)
scanf("%d",&a[i]);
int sum1=n;
int sum2=*n;
for(int i=;i<k;i++){
int d=min(sum1,a[i]/);
sum1-=d;
a[i]-=d*;
}
sum2+=sum1;
for(int i=;i<k;i++){
int d=min(sum2,a[i]/);
sum2-=d;
a[i]-=d*;
}
int tmp=sum2+sum1;
for(int i=;i<k;i++)
tmp-=a[i];
if(tmp>=)printf("YES\n");
else printf("NO\n");
}
return ;
}

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

  1. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

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

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

  3. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  4. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  5. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  6. Educational Codeforces Round 7 E. Ants in Leaves 贪心

    E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connec ...

  7. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  8. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  9. codeforces Gym 100187F F - Doomsday 区间覆盖贪心

    F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...

  10. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

随机推荐

  1. VS Extension+NVelocity系列(二)——让VS支持 NVelocity的智能提示(上)

    一.基础概念 应该庆幸的是,VS的插件是靠着MEF实现而不是MAF,这让你所做的工作减轻了许多.如果在这之前,您已经了解了MEF的原理,我想对于VS插件的编写,您应该是很容易就能理解的.看看几个VS2 ...

  2. Xcode 代码提示功能失效

    前言: 以前好像很少碰到Xcode中代码提示出问题的情况,最近经常遇到这个问题.没有了Xcode的智能提示,发现我已完全不会写代码了. 本来想吐槽下万恶的baidu,鉴于百度前端时间的各种(贴吧.竞价 ...

  3. 【转载】总结使用Unity3D优化游戏运行性能的经验

    流畅的游戏玩法来自流畅的帧率,而我们即将推出的动作平台游戏<Shadow Blade>已经将在标准iPhone和iPad设备上实现每秒60帧视为一个重要目标. 以下是我们在紧凑的优化过程中 ...

  4. 椭圆曲线加密和rsa对比

    最近在导师的要求下接手了基于欧洲标准的车联网项目中的安全层,需要学习密码学,以及网络安全的相关内容,这里做一个总结 引用的大部分内容为一个西安的大佬(哈哈我老家也是西安的),大佬主页:https:// ...

  5. HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )

    空间异面直线的距离直接套模板. 求交点:求出两条直线的公共法向量,其中一条直线与法向量构成的平面 与 另一条直线 的交点即可.还是套模板o(╯□╰)o 1.不会有两条线平行的情况. 2.两条直线可能相 ...

  6. [问题解决]ps aux中command命令相同,如何找出自己要的进程号?

    问题提出: 我们通过ps aux能够查看各个进程的状态,很多时候启动命令相同,我们没有办法判断,我们要查找的进程到底是那个? 我们该用什么方式来找出我们要操作的进程号呢? 解决步骤: 找出有可能的进程 ...

  7. C#中的&运算

    2是一个比较特殊的数. 2的1次方2 2的2次方4 2的3次方8 2的4次方16 2的5次方32 2的6次方64 2的7次方128 2的8次方256 2的9次方512 2的10次方1024 2的11次 ...

  8. Axios & Interceptors & Serialization & CORS & cookie

    Axios https://github.com/axios/axios#config-defaults Global axios defaults axios.defaults.baseURL = ...

  9. NAT64与DNS64基本原理概述

    NAT64与DNS64基本原理概述 1.NAT64与DNS64背景     在IPv6网络的发展过程中,面临最大的问题应该是IPv6与IPv4的不兼容性,因此无法实现二种不兼容网络之间的互访.为了实现 ...

  10. HDU 4746 HDOJ Mophues 2013杭州网赛I题

    比赛的时候就预感到这题能出,但是会耗时比较多.结果最后是出了,但是有更简单的题没出. 是不是错误的决策呢?谁知道呢 题目意思: 定义f(x) = x分解质因数出来的因子个数 如 x = p0 * p0 ...