CodeForces839B Game of the Rows

来源:互联网 发布:登山杖淘宝 编辑:程序博客网 时间:2024/05/24 01:28

写的有点丑,,,

#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;}