首页 > 代码库 > CodeForces839B[思维] Codeforces Round #428 (Div. 2)

CodeForces839B[思维] Codeforces Round #428 (Div. 2)

#include <bits/stdc++.h>
using namespace std;
int n, k;
const int MOD = 1000000007;
int a[105], cnt[5];
void solve() {
    int t;
    cnt[4]=n,cnt[2]=2*n;
    for(int i=0;i<k;i++){
        t=min(a[i]/4,cnt[4]);
        a[i]-=4*t;
        cnt[4]-=t;
    }
    cnt[2]+=cnt[4];
    cnt[1]+=cnt[4];
    for(int i=0;i<k;i++){
        t=min(a[i]/2,cnt[2]);
        a[i]-=2*t;
        cnt[2]-=t;
    }
    cnt[1]+=cnt[2];
    for(int i=0;i<k;i++){
        t=min(a[i],cnt[1]);
        a[i]-=t;
        cnt[1]-=t;
    }
    for(int i=0;i<k;i++) 
        if(a[i]){
            puts("NO");
            return;
        }
    puts("YES");
}
int main() {
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> a[i];
    }
    solve();
    return 0;
}

 

CodeForces839B[思维] Codeforces Round #428 (Div. 2)