CF727D.T-shirts Distribution

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

编程比赛的组织者决定向参赛者赠送T恤。本题中一共有六种不同的T恤尺码:S、M、L、XL、XXL、XXXL(按从小到大顺序列出)。T恤已预先准备就绪。对于从S到XXXL的每种尺码,你将获得该尺码的T恤数量。

在报名阶段,组织者询问了每位 nn 名参赛者所希望的T恤尺码。若某位参赛者在两种尺码之间犹豫不决,则他可以指定两个相邻的尺码——这意味着这两种尺码中的任意一种均适合他。

请编写一个程序,判断是否能为每位参赛者分配一件T恤。当然,每位参赛者必须获得符合其要求的尺码:

  • 若参赛者只指定了一个尺码,则必须为其分配该尺码;
  • 若参赛者指定了两个相邻尺码,则可为其分配其中任意一种尺码。

如果可行,程序还应找出一种合法的T恤分配方案。

输入格式

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.

输入的第一行包含六个非负整数,分别表示尺码为 S、M、L、XL、XXL、XXXL 的 T 恤件数。T 恤总数不超过 100 000100\,000。

第二行包含一个正整数 nn(1≤n≤100 0001 \leq n \leq 100\,000),表示参与者的数量。

接下来的 nn 行每行描述一位参与者指定的尺码,共 nn 行。第 ii 行包含第 ii 位参与者提供的信息:一个单独的尺码,或两个用逗号分隔(中间无空格)的尺码。若给出两个尺码,则它们按升序排列。保证用逗号分隔的两个尺码是相邻的。

输出格式

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.

如果无法为每位参与者提供一件T恤,则输出「NO」(不带引号)。

否则,输出 n+1n+1 行。第一行输出「YES」(不带引号);接下来的 nn 行中,每行输出组织者应分配给对应参与者的T恤尺码(一行一个)。参与者的顺序应与输入中的顺序一致。

若存在多种可行方案,输出任意一种即可。

输入输出样例

  • 输入#1

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

    输出#1

    YES
    XL
    M
    XXL
  • 输入#2

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

    输出#2

    NO

输入解题思路,AI测评打分。不知道怎么写?

首页