血崩- -

/*
CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2)
注意
2 7
2 2 2 2 2 2 2
这组- -
*/
#include <bits/stdc++.h>
using namespace std;
int n, n2, n4, a[105], k;
bool solve()
{
n2 = 2*k;
n4 = k;
for (int i = 1; i <= n; i++)
{
if (a[i] >= 4 && n4)
{
int t = a[i]/4;
a[i] -= min(t, n4)*4;
n4 -= min(t, n4);
}
}
for (int i = 1; i <= n; i++)
{
if (a[i] >= 2 && n2)
{
int t = a[i]/2;
a[i] -= min(t, n2)*2;
n2 -= min(t, n2);
}
}
for (int i = 1; i <= n; i++)
{
if (a[i] && n2)
{
int t = a[i];
a[i] -= min(t, n2);
n2 -= min(t, n2);
}
}
int m2 = 0, m1 = 0, m3 = 0;
for (int i = 1; i <= n; i++)
if (a[i] == 3) m3++;
else if (a[i] == 2) m2++;
else if (a[i] == 1) m1++;
int sum = m3;
if (m1 <= m2)
{
sum += m1;
m2 -= m1;
sum += m2/3*2;
m2 %= 3;
sum += m2;
}
else
{
sum += m2;
m1 -= m2;
sum += (m1+1)/2;
}
if (sum > n4) return 0;
return 1;
}
int main()
{
scanf("%d%d", &k, &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
if (solve()) puts("YES");
else puts("NO");
}

  

CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)的更多相关文章

  1. CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)

    起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #i ...

  2. CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)

    赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...

  3. Codeforces 839B - Game of the Rows

    839B - Game of the Rows 思路:先放4个的,然后再放2个的,最后再放1个的. 代码: #include<bits/stdc++.h> using namespace ...

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

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

  5. Codeforces 839B Game of the Rows【贪心】

    B. Game of the Rows time limit per test:1 second memory limit per test:256 megabytes input:standard ...

  6. 【Codeforces Round #428 (Div. 2) B】Game of the Rows

    [Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...

  7. Codeforces Round #428 (Div. 2) 题解

    题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...

  8. Codeforces Round #428 (Div. 2) D. Winter is here 容斥

    D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...

  9. Codeforces Round #428 (Div. 2)E. Mother of Dragons

    http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...

随机推荐

  1. java访问指示符

    是否 可访问 同一package 不同package 当前类 其他类 继承类 其他类 public √ √ √ √ protected √ √ √ × friendly √ √ × × private ...

  2. 记搜狗一次不成功的Python后端面试经历

    面试搜狗Python后端结束快一个月了,终于有时间来做一个简单的总结了. 简介:工作不久,基础后端岗位,一面结束,失败. 先做了几个笔试题,面试开始会根据笔试题问一些内容.下面将整理一下还能想起来的内 ...

  3. 剑指offer1: 组类型——二维数组中的查找(给定一个数字,查找是否在该数组中)

    1. 思路: 缩小范围 2. 方法: (1)要查找的数字等于数组中的数字,结束查找过程: (2)要查找的数字小于数组中的数字,去除该数字右边的数字,在剩下的数字里查找: (3)要查找的数字大于数组中的 ...

  4. tensorflow lite 之生成 tflite 模型文件

    下载最新的的tensorflow源码. 1.配置 tflite 文件转换所需环境 安装 bazel 编译工具 https://docs.bazel.build/versions/master/inst ...

  5. 8.perf top系统性能分析工具

    perf 是一个调查 Linux 中各种性能问题的有力工具. # perf --help  usage: perf [--version] [--help] COMMAND [ARGS]  The m ...

  6. shell习题第18题:检查新文件

    [题目要求] 有一台服务器作为web应用,有一个目录(/data/web/attachment)不定时会被用户上传新的文件,但是不知道什么时候会被上传.所以,需要我们每5分钟做一次检测是否有新文件生成 ...

  7. [Tarjan系列] Tarjan算法求无向图的桥和割点

    RobertTarjan真的是一个传说级的大人物. 他发明的LCT,SplayTree这些数据结构真的给我带来了诸多便利,各种动态图论题都可以用LCT解决. 而且,Tarjan并不只发明了LCT,他对 ...

  8. winfrom 保存图片

    private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); ...

  9. Docker 杂记

    1.配置阿里云加速 :可以找到各种加速URL.比如 https://tnxkcso1.mirror.aliyuncs.com/ 2.windows 配置: 3.docker info可以看到新的配置已 ...

  10. [转载]java中import作用详解

    [转载]java中import作用详解 来源: https://blog.csdn.net/qq_25665807/article/details/74747868 这篇博客讲的真的很清楚,这个作者很 ...