题目传送门:http://codeforces.com/problemset/problem/727/D
思路:贪心,注意题目限制:可以穿两种衣服号码的人,这两种号码一定是相邻的。随意按号码从小到大排序,依次满足就好。
代码如下:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <cstdlib>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll long long
#define ull unsigned long long
#define mem(n,v) memset(n,v,sizeof(n))
#define MAX 100005
#define MAXN 10005
#define PI 3.1415926
#define E 2.718281828459
#define opnin freopen("input.txt","r",stdin)
#define opnout freopen("output.txt","w",stdout)
#define clsin fclose(stdin)
#define clsout fclose(stdout)
#define haha1 cout << "haha1"<< endl
#define haha2 cout << "haha2"<< endl
#define haha3 cout << "haha3"<< endl
const int INF = 0x3f3f3f3f;
const ll INFF = 0x3f3f3f3f3f3f3f3f;
const double pi = 3.141592653589793;
const double inf = 1e18;
const double eps = 1e-8;
const ll mod = 1e18;
const ull mx = 133333331;
/**************************************************************************/
map<string,int>S;
int v[10];
string T[10];
void init()
{
T[0] = "S";
T[1] = "M";
T[2] = "L";
T[3] = "XL";
T[4] = "XXL";
T[5] = "XXXL";
S["S"] = 0;
S["M"] = 1;
S["L"] = 2;
S["XL"] = 3;
S["XXL"] = 4;
S["XXXL"] = 5;
}
void rd(){
int x;
for(int i=0;i<6;i++){
cin >> x;
v[i] = x;
}
}
struct tshirt
{
int a,b,id;
tshirt() : a(-1),b(-1),id(-1) {}
friend bool operator < (const struct tshirt a,const struct tshirt b){
return a.a<b.a;
}
}tshirts[MAX];
int ans[MAX];
int main()
{
opnin;
opnout;
init();
rd();
int n;
cin >> n;
string str;
int cnt = 0;
bool flag = true;
// cout << n<< endl;
for(int i=0;i<n;i++){
// haha3;
cin >> str;
string a,b;
int j = 0;
while(j < str.size() && str[j] != ',') a += str[j++];
// cout << a << endl;
if(j++ != str.size()){
while(j < str.size() && str[j] != ',') b += str[j++];
// cout << b << endl;
tshirts[cnt].a = S[a];
tshirts[cnt].id = i;
tshirts[cnt++].b = S[b];
}
else{
// cout << "1 " << a << endl;
if(v[S[a]]){
v[S[a]]--;
ans[i] = S[a];
// haha3;
}
else flag = false;
}
}
// haha2;
if(!flag){
cout << "NO" << endl;
return 0;
}
sort(tshirts,tshirts+cnt);
// haha1;
for(int i=0;i<cnt;i++){
// cout << "i: " << i << ' ' << tshirts[i].a << endl;
if(v[tshirts[i].a]){
v[tshirts[i].a]--;
ans[tshirts[i].id] = tshirts[i].a;
// cout << "i: " << i << ' ' << tshirts[i].a << endl;
}
else if(v[tshirts[i].b]){
v[tshirts[i].b]--;
ans[tshirts[i].id] = tshirts[i].b;
// cout << "i: " << i << ' ' << tshirts[i].b << endl;
}
else flag = false;
}
if(!flag){
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
for(int i=0;i<n;i++)
cout << T[ans[i]] << endl;
clsin;
clsout;
return 0;
}