CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)
血崩- -
/* 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"); }
我自倾杯,君且随意