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 XXXLyou 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 sizesS, 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
0 1 0 1 1 0
3
XL
S,M
XL,XXL
output
YES
XL
M
XXL
input
1 1 2 0 1 1
5
S
M
S,M
XXL,XXXL
XL,XXL
output
NO
分析:因为1个人最多选两件型号相邻的T恤,所以直接从小到大的型号贪心即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<ll,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,c[];
struct node
{
string a,b;
int ca;
}op[maxn];
string d;
bool flag=true;
string ca[]={"S","M", "L", "XL", "XXL", "XXXL"};
int gao(string a)
{
int i;
rep(i,,)if(a==ca[i])return i+;
}
vi v[];
int main()
{
int i,j;
rep(i,,)scanf("%d",&c[i]);
scanf("%d",&n);
rep(i,,n)
{
cin>>d;
int xx=;
for(j=;d[j];j++)
{
if(d[j]==',')
{
xx=j;
break;
}
}
if(xx)
{
op[i].a=d.substr(,xx);
op[i].b=d.substr(xx+);
v[gao(d.substr(,xx))].pb(i);
}
else
{
if(--c[gao(d)]<)
{
flag=false;
break;
}
op[i].a=d;
op[i].ca=;
}
}
for(i=;i<=;i++)
{
for(int x:v[i])
{
if(c[i]>)
{
c[i]--;
op[x].ca=;
}
else if(c[i+]>)c[i+]--,op[x].ca=;
else
{
flag=false;
break;
}
}
}
if(flag)
{
puts("YES");
rep(i,,n)
{
if(op[i].ca==)cout<<op[i].a<<endl;
else cout<<op[i].b<<endl;
}
}
else puts("NO");
//system("Pause");
return ;
}

T-shirts Distribution的更多相关文章

  1. 齐夫定律, Zipf's law,Zipfian distribution

    齐夫定律(英语:Zipf's law,IPA英语发音:/ˈzɪf/)是由哈佛大学的语言学家乔治·金斯利·齐夫(George Kingsley Zipf)于1949年发表的实验定律. 它可以表述为: 在 ...

  2. CloudSim4.0报错NoClassDefFoundError,Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.distribution.UniformRealDistribution

    今天下载了CloudSim 4.0的代码,运行其中自带的示例程序,结果有一部分运行错误: 原因是找不到org.apache.commons.math3.distribution.UniformReal ...

  3. Wishart distribution

    Introduction In statistics, the Wishart distribution is generalization to multiple dimensions of the ...

  4. distribution 中一直在运行 waitfor delay @strdelaytime 语句

    Replication 自动创建来一个 Job:Replication monitoring refresher for distribution,这个Agent执行一个sp: dbo.sp_repl ...

  5. Distribution2:Distribution Writer

    Distribution Writer 调用Statement Delivery 存储过程,将Publication的改变同步到Subscriber中.查看Publication Properties ...

  6. Distribution1:Distribution Reader

    在transactional replication中,在publication中执行了一个更新,例如:update table set col=? Where ?,如果table中含有大量的数据行, ...

  7. 设置Distribution clean up 每次删除Command的数量

    Replication Job “Distribution clean up: distribution” 默认设置是,每10minutes运行一次,每次删除2000个Command.这对于有1.9亿 ...

  8. Your account already has a valid iOS Distribution certificate!

    iOS 发布提交出现:Your account already has a valid iOS Distribution certificate!问题解决 转载的链接   http://www.jia ...

  9. Replication-Replication Distribution Subsystem: agent xxxxxx failed. Column names in each table must be unique

    最近遇到一个关于发布订阅(Replication)的奇葩问题,特此记录一下这个案例.我们一SQL SERVER数据库服务器出现大量告警.告警信息如下所示: DESCRIPTION: Replicati ...

  10. SQL Server删除distribution数据库

    在数据库服务器删除复制(发布订阅)后,如何删除掉数据库distribution呢?如果你通过SSMS工具去删除数据库distribution,你会发现根本没有删除选项. 下面介绍一下删除distrib ...

随机推荐

  1. 戏说HTML5(转)

    如果有非技术人员问你,HTML5是什么,你会怎么回答? 新的HTML规范... 给浏览器提供了牛逼能力,干以前不能干的事...(确切地说应该是给浏览器规定了许多新的接口标准,要求浏览器实现牛逼的功能. ...

  2. jquery makearray()使用

    makearray(),转换一个类似数组的对象成为真正的JavaScript数组.首先看看jquery中array的定义 makeArray: function( arr, results ) { v ...

  3. hdu_5507_GT and strings(AC自动机)

    题目链接:hdu_5507_GT and strings 题意:给n个字符串和q个询问,每个询问给两个数字x,y,问1.x是否为y的子序列,2.x是否为y的子串,是输出1,否则输出0,每个询问输出2个 ...

  4. 二、ASP.NET MVC Controller 控制器(一:深入解析控制器运行原理)

    阅读目录: 1.开篇介绍 2.ASP.NETMVC Controller 控制器的入口(Controller的执行流程) 3.ASP.NETMVC Controller 控制器的入口(Controll ...

  5. 文件传送,如此简单--ESFramework 4.0 快速上手(13)

    在所有的通信系统中,文件传送是最常见也是最重要的功能之一,ESFramework对文件传送的强大支持也是其亮点之一,使用ESFramework可以非常轻松地实现与文件传送相关的所有需求.ESPlus. ...

  6. Excel教程(7) - 工程函数

    BESSELI 用途:返回修正 Bessel 函数值,它与用纯虚数参数运算 时的 Bessel 函数值相等. 语法:BESSELI(x,n)     参数:X 为参数值.N 为函数的阶数.如果 n 非 ...

  7. Oracle SQL 内置函数大全

    SQL中的单记录函数 1.ASCII 返回与指定的字符对应的十进制数;SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ...

  8. validator验证

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  9. UVA 11021 /概率

    题意: 有k只鸟,每只鸟只能活一天,它可以在死之前生[0,n-1]只鸟,生出x只鸟的概率是p[x].问m天后所有的鸟都时光的概率.(m天之前就死了的也算上). 输入:T.n.k.m. 题解: 每只鸟的 ...

  10. postgresql删除属性

    PostgreSQL update and delete property from JSONB column up vote 2 down vote favorite From this artic ...