atcoder#ABC271D. [ABC271D] Flip and Adjust
[ABC271D] Flip and Adjust
Score : points
Problem Statement
There are cards with an integer written on each side. Card has an integer written on the front and an integer written on the back.
You may choose whether to place each card with its front or back side visible.
Determine if you can place the cards so that the sum of the visible integers exactly equals . If possible, find a placement of the cards to realize it.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
First, print Yes
if you can make the sum of the visible integers exactly equal , and No
otherwise, followed by a newline.
Additionally, if such a placement is possible, print a string of length consisting of H
and T
that represents the placement of the cards to realize it.
The -th character should be H
if the -th card should be placed with its front side visible, and T
with its back.
If there are multiple possible placements to realize the sum, printing any of them is accepted.
3 11
1 4
2 3
5 7
Yes
THH
For example, the following placements make the sum of the visible integers exactly equal :
- Place the -st card with its front side visible, -nd with its back, and -rd with its back.
- Place the -st card with its back side visible, -nd with its front, and -rd with its front.
Therefore, outputs like HTT
and THH
are accepted.
5 25
2 8
9 3
4 11
5 1
12 6
No
You cannot place the cards so that the sum of the visible integers exactly equals .