codeforces 839 B Game of the Rows

题目链接:http://codeforces.com/contest/839/problem/B

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn = 100 + 5;

int n, k;
int a[maxn];

void display(int n){
    for (int i = 0; i < n; ++i){
        printf("(%d)%d ", i + 1, a[i]);
    }
    printf("\n");
}

int main(){
    scanf("%d%d", &n, &k);
    for (int i = 0; i < k; ++i){
        scanf("%d", a + i);
    }
    int four = n, two = 2 * n, one;
    int t;
    //先往3,4,5,6安排士兵
    for (int i = 0; i < k; ++i){
        t = min(a[i] / 4, four);
        four -= t;
        a[i] -= t * 4;
        if (four == 0){
            break;
        }
    }
    //把剩余的四连座分解为一个双座和一个单座
    two += four;
    one = four;
    four = 0;
    //再往1,2  7,8上安排士兵
    for (int i = 0; i < k; ++i){
        t = min(a[i] / 2, two);
        two -= t;
        a[i] -= t * 2;
        if (two == 0){
            break;
        }
    }
    int s = 0;
    //统计剩余士兵数量(每个group最多还剩一名士兵)
    for (int i = 0; i < k; ++i){
        s += a[i];
    }
    //单人座和双人座都还能坐一个士兵,若无法坐下全部士兵,则没有满足题意的策略
    bool status = (s <= (two + one));
    printf("%s\n", status ? "YES": "NO");
    return 0;
}
发布了10 篇原创文章 · 获赞 3 · 访问量 870

猜你喜欢

转载自blog.csdn.net/ErrorNam/article/details/82976368