这道题巨猥琐,场上很多人都被hack了
正解应该是一个我也不知道是怎么过的贪心
首先按照人数从大到小排序
如果有四个四个的,就优先放进大横排
如果有三个三个的,也优先放进大横排,你会发现四个和三个是相似的,因为都要占用一整个大横排,或是占用两个小横排
然后是两个两个的,优先放进小横排,如果不够,优先和已经坐过一个人的大横排拼座,否则占领一个大横排
最后是一个一个的,优先和有两个人的大横排拼座,然后是占领一个大横排,最后是占领一个小横排
别问我是怎么想的,这是通过尝试能过的贪心策略
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;
const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;
int n,k;
int a[1048];
int c1,c2,c3;
bool cmp(int x,int y)
{
return x>y;
}
int main ()
{
int i;
scanf("%d%d",&n,&k);
for (i=1;i<=k;i++) scanf("%d",&a[i]);
sort(a+1,a+k+1,cmp);
c1=n;c2=n*2;
for (i=1;i<=k;i++)
{
while (a[i]>=4 && c1>0)
{
c1--;
a[i]-=4;
}
while (a[i]>=3 && c1>0)
{
c1--;
a[i]-=3;
}
while (a[i]>=2 && c2>0)
{
c2--;
a[i]-=2;
}
while (a[i]>=2 && c1>0)
{
c1--;
c3++;
a[i]-=2;
}
while (a[i]>0 && c3>0)
{
c3--;
a[i]--;
}while (a[i]>0 && c1>0)
{
c1--;
c2++;
a[i]--;
}
while (a[i]>0 && c2>0)
{
c2--;
a[i]--;
}
if (a[i]>0)
{
printf("NO\n");
return 0;
}
}
printf("YES\n");
return 0;
}