血崩- -

/*
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 CGLib代理

    转载自   cglib之Enhancer 1. 背景 cglib库的Enhancer在Spring AOP中作为一种生成代理的方式被广泛使用.本文针对Enhancer的用法以实际代码为例作一些介绍. ...

  2. mingw-w64 gcc std::thread 行为异常

    我用的 ming-w64 gcc 是通过 MSYS2 安装的,包名是 mingw-w64-x86_64-gcc,版本 9.2.0-2. 我发现 std::thread 行为异常. int main() ...

  3. Django-djangorestframework-渲染模块

    目录 渲染模块 渲染模块的效果 源码分析 如何自定义配置使用渲染类 自定义渲染模块 渲染模块 可以根据用户请求 URL 或 用户可接受的类型,筛选出合适的 渲染组件. reponse 数据 json ...

  4. 【转】三种方法让你在I2C通信中同时和多个从机通信

    ref:http://tieba.baidu.com/p/3769008030 对于不同地址的模块就不用多说了,直接分别对其地址进行通信即可.那么若拿到相同地址的模块,或者直接是相同的多个模块怎么办呢 ...

  5. nginx运行基本指令

    测试配置文件: 安装路径下的/nginx/sbin/nginx -t启动: 安装路径下的/nginx/sbin/nginx停止 安装路径下的/nginx/sbin/nginx -s stop 或者是: ...

  6. KeyValuePair<string, string>

    ; #region CUP Method /// <summary> /// 请求与响应的超时时间 /// </summary> static public int Timeo ...

  7. Spring 自定义Bean 实例获取

    一.通过指定配置文件获取, 对于Web程序而言,我们启动spring容器是通过在web.xml文件中配置,这样相当于加载了两次spring容器 ApplicationContext ac = new ...

  8. springboot-异步、发送邮件(二)

    @Test //发送复杂邮件 void contextLoads2() throws MessagingException { MimeMessage mimeMessage = mailSender ...

  9. 图片样式加hover特效

    之前有个尴尬的事情发生,我不知道如何将文字放在图片右边,我想了个麻烦且愚蠢的办法,后来才知道只需要将图片居左就可以达到效果.....不说了看下面 需要实现的效果: 很简单, <img src=& ...

  10. windows批处理来执行java程序

    新建后缀名为.bat的文件,然后用记事本编辑,如果用sublime高级记事本编辑最好. @echo off % mshta vbscript:CreateObject()(window.close)& ...