Codeforces 839B

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 ≤ 100001 ≤ 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.


题意如上所示。

题解:贪心,首先很容易想到对于每组中有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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是Daenerys Targaryen Wallpaper Chrome Theme的扩展 丹尼尔斯·塔加里安(Ranaegar Targaryen)的妹妹,国王埃里斯·塔加里安(Aerys Targaryen)的女儿,是《权力的游戏》和《冰与火之歌》中的主角之一。 在属于罗伯特·巴拉森(Robert Baratheon)篡夺之前,她属于一个统治着维斯特罗大陆数百年的家庭。 由于现为七个王国之王的罗伯特·巴拉森(Robert Baratheon)想要杀死活着的每一个塔加里安人,丹妮莉丝小时候就搬到了另一个名为埃索斯的大陆。 随着她的成长,她了解到了所有关于她出生的维斯特洛大陆的知识。 如果安装我们的扩展程序,您会得到什么? 只需单击“安装”按钮,即可确保自己非常有趣的Internet浏览。 我们进行扩展的目的纯粹是为了娱乐用户。 如果要阅读我们提供的功能的完整列表,请阅读以下列表。 变化的墙纸(打开新标签后,永远不会获得相同的墙纸两次)时钟小部件(显示时间和日期,已调整为您自己的时区)Cusom搜索栏(已连接到Google的搜索引擎,几乎100%透明)网站建议(某些(世界上最有趣的网站,供您娱乐)此扩展程序可以替换您在打开新标签页时看到的页面显示通知阅读和更改书签管理您的应用程序,扩展程序和主题在此处查看有关Daenerys的文章:http:// newtabsy .com / daenerys-targaryen-wallpaper-chrome-theme / 支持语言:English
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值