题目:http://codeforces.com/contest/839/problem/B
题意:让你将所有的士兵分配位置,不同group的不能相邻,相邻的含义是类似{1,2},{3,4,5,6},{7,8}。
思路:贪心先放完{3,4,5,6}4个的,然后再考虑2个的,另外要注意4个的可以放2个加1个。
代码:
#include<bits/stdc++.h>
using namespace std;
int a[10005];
int n,k;
int main()
{
scanf("%d%d",&n,&k);
//int sum = 0;
for(int i = 0;i < k;i++)
{
scanf("%d",&a[i]);
}
int m = n*2;
for(int i = 0;i < k;i++)
{
int d = min(a[i]/4,n);
n -= d;
a[i] -= d*4;
}
m += n;
for(int i = 0;i < k;i++)
{
int d = min(a[i]/2,m);
m -= d;
a[i] -= d*2;
}
int sum = n+m;
for(int i = 0;i < k;i++)
sum -= a[i];
if(sum >= 0)
printf("YES\n");
else
printf("NO\n");
/*
for(int i = 1;i <= k;i++)
{
}
int u = n*2,v = n;
int sum = 0;
for(int i = 1;i <= k;i++)
{
if(u > 0)
{
u -= (a[i]+1)/2;
}
else
v -= (a[i]+1)/2;
}
if(sum <= n)
printf("YES\n");
else
printf("NO\n");*/
}