Clothes Hangers
InterviewTime limit1sMemory limit256 MB
Given each hanger's type and the counts of tops and bottoms, decide whether all clothes can be hung and print one valid assignment if so.
- Level
Easy2 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Problem
Gyeonggi Science High School has a formidable department called the Self-Governance Department. One of its main duties is to enter assigned dormitory rooms in the morning and check whether the rooms are tidy. Eunho is a member of this department and must inspect every room in the dormitory. However, clothes were scattered all over each room he checked, and the rooms were badly messy. So Eunho decided to hold a dormitory cleaning day and tidy up all the clothes.
Eunho surveyed the clothes hangers at Gyeonggwak dormitory and found three kinds. One kind holds only tops, another holds only bottoms, and the last kind holds both tops and bottoms. A single hanger can hold only one top or only one bottom.
Before tidying up, Eunho wants to check whether the hangers are enough to hold all the clothes. He surveyed the number of tops and bottoms, and the number and kinds of hangers at Gyeonggwak dormitory. Surprisingly, the number of hangers and the number of clothes are the same. There are too many clothes to sort by hand, so Eunho wants a program that determines whether all the clothes can be hung. If they can, he also wants to know how to hang them.
Eunho had an urgent appointment with Geonpyo and left the implementation of this program to you. Write the program on Eunho's behalf.
Input
The first line contains the number of hangers .
The second line contains integers. The -th integer is the kind of the -th hanger.
1 means a top-only hanger, 2 means a bottom-only hanger, and 3 means a hanger that can hold both tops and bottoms.
The last line contains two integers and . is the number of tops, and is the number of bottoms. It is guaranteed that .
Output
If all the given tops and bottoms can be hung on the hangers, print YES on the first line. Otherwise, print NO.
If all the clothes can be hung, print on the second line a string of length showing how each hanger was used. The -th character of the string is the kind of clothes hung on the -th hanger: U for a top and D for a bottom. (Do not print the single quotes.)
The characters must be printed in uppercase.
Constraints