最近太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. vue理解$nextTick

    首先要明确: Vue 实现响应式并不是数据发生变化之后 DOM 立即变化,而是按一定的策略进行 DOM 的更新. $nextTick 是在下次 DOM 更新循环结束之后执行延迟回调,在修改数据之后使用 ...

  2. USACO Section1.3 Wormholes 解题报告

    wormhole解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------- ...

  3. Windows下安装PHP及开发环境配置

    一.Apache 因为Apache官网只提供源代码,如果要使用必须得自己编译,这里我选择第三方安装包Apache Lounge. 1. 进入Apachelounge官方下载地址:http://www. ...

  4. input()报错:TypeError: '>=' not supported between instances of 'str' and 'int'

    今天学习python基础—分支与循环,接触到了if.在练习一个if语句的时候,出现了错误. 题目是: 根据分数划分成四个级别:优秀.良好.及格.不及格,分数是72: grade = 72if grad ...

  5. navmesh自动寻路

    一个导航网格(也就是Navmesh)是世界几何体简化的表示法,被游戏代理用于在世界中进行导航.通常,代理(agent )有一个目标,或一个目的地,它试图找到一个路径,然后沿路径导航到达目标.这个过程被 ...

  6. Python MySQLdb 模块使用方法

    import MySQLdb 2.和数据库建立连接 conn=MySQLdb.connect(host="localhost",user="root",pass ...

  7. CodeForces C. Maximal Intersection

    http://codeforces.com/contest/1029/problem/C You are given nn segments on a number line; each endpoi ...

  8. macOS Mojave 深色模式

    macOS Mojave 深色模式 mac 关闭 深色模式 https://support.apple.com/zh-cn/HT208976 https://www.apple.com/cn/maco ...

  9. 忽略node_modules目录

    如上图所示添加node_modules目录到忽略文件列表里面,点击应用就可以了.

  10. npm下载包失败的几个原因

    1. 可能是由于网络问题导致下载包失败,因为qiang,所以,直接使用npm有些情况会导致下载包失败,使用cnpm源或者yarn下载等方法可以解决这个问题. 2. 这个包不存在,检查一下包的拼写或者路 ...