写于newbee被李逵三比零之后.
关了直播,改了一个地方,就a了,可能我不要想太多无关的东西把.
这题讲实话我觉得挺难做的,如果不是在cf上可以看到数据,可能还要很久我才能a.
我的思路是把每一个军团的人,都分成三种,4个人一组,两个人一组,一个人一组,这样的话呢,两个人和一个人的组,每个军团最多一个.(关键)
然后就是贪心的策略,飞机中间的座位,一定要给四人连坐,因为这样不会浪费位置.然后如果四人座坐不完四人组,四人组就拆开,去坐两边.
然后处理二人组,同理,二人组要优先坐两边的位置.
然后一人,如果两边还有剩余,就让他们坐过去.
最后,我们的中间四人座,只坐了四人组对吧?因为这个地方,一排最多可以坐三个人,所以要特殊考虑,余下的二人组,最多占满同一侧,其他就可以给一个人了,但是注意到,二人组也可以拆开,所以就又要加一层判断.
详见代码.
/* xzppp */
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <list>
#include <math.h>
#include <iomanip>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mp make_pair
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 10000;
const int INF = 0x7fffffff;
const int MOD = 1e9+7;
struct
{
int p1,p2,p4;
}all[MAXN+17];
int main()
{
//FFF
int n,k;
cin>>n>>k;
int h4 = n,h2 = 2*n;
for (int i = 0; i < k; ++i)
{
int temp;
cin>>temp;
all[i].p4 = temp/4;
temp -= all[i].p4*4;
all[i].p2 = temp/2;
temp -= all[i].p2*2;
all[i].p1 = temp;
}
bool can = true;
int r2=0,r1=0;
for (int i = 0; i < k; ++i)
{
if(h4>=all[i].p4)
h4 -= all[i].p4;
else
{
all[i].p4 -= h4;
h4 = 0;
if(2*h2>=all[i].p4)
h2 -= 2*all[i].p4;
else
can = false;
}
r2 += all[i].p2;
r1 += all[i].p1;
}
if(h2>=r2)
{
h2 -= r2;
r2 = 0;
}
else
{
r2 -= h2;
h2 = 0;
}
if(h2>=r1)
{
h2 -= r1;
r1 = 0;
}
else
{
r2 -= h2;
h2 = 0;
}
if(!(h4>=r2&&r1+r2<=2*h4))
{
if(!(r2>h4&&(r2-h4)*2+r1<=h4))
can = false;
}
if(can)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}