Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.
A row in the airplane
Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.
Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.
#include
#include
#include
#include
using namespace std;
int K[10000];
int main(void)
{
//freopen("input.txt","r",stdin);
int n,k;
cin>>n>>k;
int left4=n;
int left2=n*2;
int left1=0;
for(int i=0;i
{
cin>>K[i];
}
for(int i=0;i
{
if(K[i]>=4)
{
if(left4>=K[i]/4)
{
left4-=K[i]/4;
K[i]=K[i]%4;
}
else
{
K[i]=K[i]-left4*4;
left4=0;
left2-=K[i]/4*2;
K[i]=K[i]%4;
}
}
}
for(int i=0;i
{
if(K[i]==3)
{
if(left4>0)
{
left4--;
}
else
{
left2-=2;
}
}
}
for(int i=0;i
{
if(K[i]==2)
{
if(left4>0)
{
left4--;
left1++;
}
else
{
left2--;
}
}
}
for(int i=0;i
{
if(K[i]==1)
{
if(left4>0)
{
left4--;
left2++;
}
else if(left1>0)
{
left1--;
}
else
{
left2--;
}
}
}
if(left2<0)
{
cout<<"NO";
}
else
{
cout<<"YES";
}
return 0;
}