CodeForces 839B Game of the Rows

写的有点丑,,,

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<ctype.h>
#include<vector>
#include<algorithm>
// cout << "  ===  " << endl;

using namespace std;
typedef long long ll;
const int maxn = 100 + 7, INF = 0x3f3f3f3f, mod = 1e9+7;
int n, k, n1, n2;
int x;

int main() {
    scanf("%d%d", &n, &k);
    n1 = n, n2 = n * 2;
    int x1 = 0, x2 = 0;
    for(int i = 0; i < k; ++i) {
        scanf("%d", &x);
        while(x > 0) {
            if(x >= 3) {
                if(n1) {
                    x -= 4;
                    n1--;
                }
                else if(n2 >= 2){
                    x -= 4;
                    n2 -= 2;
                }
                else {
                    cout << "NO" << endl;
                    return 0;
                }
            }
            if(x == 1) {
                x1++;
                x -= 1;
            }
            else if(x == 2) {
                if(n2) {
                    n2--;
                    x -= 2;
                }
                else {
                    x2++;
                    x -= 2;
                }
            }
        }
    }
    //cout << x1 << " ++ " << x2 << endl;
    if(x2 > 0) {
        if(x2 > n1) {
            x2 -= n1;
            x1 += 2 * x2;
            x1 -= n1;
            n1 = 0;
        }
        else {
            n1 -= x2;
            x1 -= x2;
        }
    }
    if(x1 <= 0) {
        cout << "YES" << endl;
        return 0;
    }
    else if(2 * n1 + n2 >= x1){
        cout << "YES" << endl;
        return 0;
    }
    else {
        cout << "NO" << endl;
        return 0;
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值