Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) D

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
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
题意:那个有6种不同的衣服。有些人尺码确定的,有些人则位于中间,比如XL~XXL,问怎么分配
解法:
1 优先分配单独的
2 两种选择的优先权是"S,M","M,L","L,XL","XL,XXL","XXL,XXXL",(高->低)
3 然后...其实就这样,再改改输出就行
4 当时认为是剩余多的先选WA到死
复制代码
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 map<string,int>Mp,mp;
 4 int a[10];
 5 string s[100010];
 6 string s2[100010];
 7 string s3[7]={" ","S","M","L","XL","XXL","XXXL"};
 8 string ss[6]={" ","S,M","M,L","L,XL","XL,XXL","XXL,XXXL"};
 9 vector<string>Ve;
10 int main(){
11     mp["S"]=1;
12     mp["M"]=2;
13     mp["L"]=3;
14     mp["XL"]=4;
15     mp["XXL"]=5;
16     mp["XXXL"]=6;
17     Mp["S,M"]=1;
18     Mp["M,L"]=2;
19     Mp["L,XL"]=3;
20     Mp["XL,XXL"]=4;
21     Mp["XXL,XXXL"]=5;
22     for(int i=1;i<=6;i++){
23         cin>>a[i];
24     } //cout<<a[mp["XXL"]]<<endl;
25     int m;
26     cin>>m;
27     for(int i=1;i<=m;i++){
28         cin>>s[i];
29         if(Mp[s[i]]==0){
30             a[mp[s[i]]]--;
31         }
32     }
33     for(int i=1;i<=6;i++){
34             if(a[i]<0){
35                 cout<<"NO"<<endl;
36                 return 0;
37             }
38         }
39     for(int i=1;i<=5;i++){
40         for(int j=1;j<=m;j++){
41             if(ss[i]==s[j]){
42                 if(a[Mp[s[j]]]){
43                     a[Mp[s[j]]]--;
44                     s[j]=s3[Mp[s[j]]];
45                 }else if(a[Mp[s[j]]+1]){
46                     a[Mp[s[j]]+1]--;
47                     s[j]=s3[Mp[s[j]]+1];
48                 }else{
49                     cout<<"NO"<<endl;
50                     return 0;
51                 }
52             }
53         }
54     }
55     cout<<"YES"<<endl;
56     for(int i=1;i<=m;i++){
57         cout<<s[i]<<endl;
58     }
59     return 0;
60 }
复制代码

 

 
posted @   樱花落舞  阅读(321)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示