当前位置: 首页 > 工具软件 > t-shirts > 使用案例 >

Codeforces 727D-T-shirts Distribution (字符串 贪心)

司空高义
2023-12-01

D. T-shirts Distribution

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size.

During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him.

Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size:

  • the size he wanted, if he specified one size;
  • any of the two neibouring sizes, if he specified two sizes.

If it is possible, the program should find any valid distribution of the t-shirts.

Input

The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000.

The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants.

The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring.

Output

If it is not possible to present a t-shirt to each participant, print «NO» (without quotes).

Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input.

If there are multiple solutions, print any of them.

Examples

input

Copy

0 1 0 1 1 0
3
XL
S,M
XL,XXL

output

Copy

YES
XL
M
XXL

input

Copy

1 1 2 0 1 1
5
S
M
S,M
XXL,XXXL
XL,XXL

output

Copy

NO

题意:有六种T恤s,m,l,xl,xxl,xxxl,有些人知道自己需要的那一种T恤,有些人只知道大致的尺码范围但是给出的尺码范围是固定的只能是相邻两个尺码,然后要求你去给出一个方案使得每个人都有T恤穿 那么本题的做法就呼之欲出了,简单贪心,单个的尺码有就给,没有就不行,两个的话先从小的尺码开始找,小的先满足了然后再满足大的尺码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register ll
#define inf 2147483647
#define lb(x) (x&(-x))
ll sz[200005],n;
template <typename T> inline void read(T& x)
{
    x=0;char ch=getchar();ll f=1;
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}x*=f;
}
inline ll query(ll x){ll res=0;while(x){res+=sz[x];x-=lb(x);}return res;}
inline void add(ll x,ll val){while(x<=n){sz[x]+=val;x+=lb(x);}}//第x个加上val
map<string,ll>p;
string s[100005];
ll vis[100005];
vector<string>v;
struct wunai
{
	string p;
	ll num;
	inline bool operator<(const wunai&a)const{
		return num<a.num;
	}
}ans[100005];
int main()
{
	ll a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	p["S"]=a,p["M"]=b,p["L"]=c,p["XL"]=d,p["XXL"]=e,p["XXXL"]=f;
	ll x,check=0;
	cin>>x;
	for(rg i=1;i<=x;i++)
	{
		cin>>s[i];
	}
	for(rg i=1;i<=x;i++)
	{
		ll flag=0;
		for(rg j=0;s[i][j];j++)
		{
			if(s[i][j]==',')
			{
				flag=1;
				break;
			}
		}
		if(!flag)
		{
			if(p[s[i]])p[s[i]]--,vis[i]=1,ans[i].p=s[i];
			else 
			{
				check=1;
				break;
			}
		}
	}
	if(check==1)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	//
	for(rg i=1;i<=x;i++)
	{
		if(!vis[i])
		{
			if(s[i][0]=='S')
			{
				if(p["S"])p["S"]--,vis[i]=1,ans[i].p="S";
				else  if(p["M"])p["M"]--,vis[i]=1,ans[i].p="M";
				else
				{
					check=1;
					break;
				}
			}
		}
	}
	if(check==1)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	

	
	for(rg i=1;i<=x;i++)
	{
		if(!vis[i])
		{
			if(s[i][0]=='M')
			{
				if(p["M"])p["M"]--,vis[i]=1,ans[i].p="M";
				else  if(p["L"])p["L"]--,vis[i]=1,ans[i].p="L";
				else
				{
					check=1;
					break;
				}
			}
		}
	}
	if(check==1)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	
	//
	for(rg i=1;i<=x;i++)
	{
		if(!vis[i])
		{
			if(s[i][0]=='L')
			{
				if(p["L"])p["L"]--,vis[i]=1,ans[i].p="L";
				else  if(p["XL"])p["XL"]--,vis[i]=1,ans[i].p="XL";
				else
				{
					check=1;
					break;
				}
			}
		}
	}
	if(check==1)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	//
	
	for(rg i=1;i<=x;i++)
	{
		if(!vis[i])
		{
			if(s[i][0]=='X'&&s[i][1]=='L')
			{
				if(p["XL"])p["XL"]--,vis[i]=1,ans[i].p="XL";
				else  if(p["XXL"])p["XXL"]--,vis[i]=1,ans[i].p="XXL";
				else
				{
					check=1;
					break;
				}
			}
		}
	}
	if(check==1)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	//
	for(rg i=1;i<=x;i++)
	{
		if(!vis[i])
		{
			if(s[i][0]=='X'&&s[i][1]=='X'&&s[i][2]=='L')
			{
				if(p["XXL"])p["XXL"]--,vis[i]=1,ans[i].p="XXL";
				else  if(p["XXXL"])p["XXXL"]--,vis[i]=1,ans[i].p="XXXL";
				else
				{
					check=1;
					break;
				}
			}
		}
		v.push_back(ans[i].p);
	}
	
	if(check==1)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	if(!check)
	{
		cout<<"YES"<<endl;
		for(auto it:v)cout<<it<<endl;
		
	}
    return 0;
    
}

 

 类似资料: