Codeforces 727D-T-shirts Distribution

来源:互联网 发布:秃鹰配件名称及数据 编辑:程序博客网 时间:2024/05/15 17:33

原题链接

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: SMLXLXXLXXXL (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 sizesSMLXLXXLXXXL, 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 03XLS,MXL,XXL
output
YESXLMXXL
input
1 1 2 0 1 15SMS,MXXL,XXXLXL,XXL
output
NO

统计每种衣服的数量,用cnt数组表示。先为只有一种选择的人分配衣服,更新cnt[].最后剩下的人每个人对衣服的选择有两个,总共五种选择,其中五种选择中S衣服只出现一次"S,M"那么把所有S的衣服分配给这种选择的人,不够的话用M衣服来补。那么剩下四种选择,其中M衣服只出现一次"M.L",分配方式一样

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <map>#include <vector>#define maxn 5005#define MOD 1000000007using namespace std;typedef long long ll;char s1[5][10] = {"S,M", "M,L", "L,XL", "XL,XXL", "XXL,XXXL"};char s2[6][10] = {"S", "M", "L", "XL", "XXL", "XXXL"};  char s3[100005][10];int cnt[6];int main(){//freopen("in.txt", "r", stdin); for(int i = 0; i < 6; i++)   scanf("%d", cnt+i);int n;scanf("%d", &n); for(int i = 0; i < n; i++){scanf("%s", s3[i]);for(int j = 0; j < 6; j++){if(strcmp(s3[i], s2[j]) == 0){cnt[j]--;break;}}}for(int i = 0; i < 6; i++){if(cnt[i] < 0){puts("NO");return 0;}}for(int i = 0; i < 5; i++){for(int j = 0; j < n; j++){if(strcmp(s1[i], s3[j]) == 0){if(cnt[i] > 0){cnt[i]--;strcpy(s3[j], s2[i]);}else if(cnt[i+1] > 0){cnt[i+1]--;strcpy(s3[j], s2[i+1]);}else{puts("NO");return 0;}}}}puts("YES");for(int i = 0; i < n; i++) puts(s3[i]);return 0;}



0 0