#abc271d. D - Flip and Adjust
D - Flip and Adjust
Score : points
问题描述
设有 张卡片,每张卡片上都写有一个整数。第 张卡片 的正面写着整数 ,背面则写着整数 。
你可以选择将每张卡片正面或反面朝上放置。
判断是否存在一种放置方式,使得所有可见整数之和恰好等于 。如果可能,请找出实现这一目标的卡片放置方案。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
3 11
1 4
2 3
5 7
Sample Output 1
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.
Sample Input 2
5 25
2 8
9 3
4 11
5 1
12 6
Sample Output 2
No
You cannot place the cards so that the sum of the visible integers exactly equals .
update @ 2024/3/10 11:25:35