No.1724 [Cherry 3rd Tune A] Lápiz labial de Sonia
Notice
If the judge result isQLE, there may be an error in the problem or in the judge. Please report it.
Problem Statement
Sonia is going to buy $N$ types of cosmetics. Each of the $N$ types of cosmetics is sold by both Company A and Company B.
For each type of cosmetic, Sonia has decided to buy exactly one of "Company A's product" or "Company B's product" (she cannot choose to buy neither).
For the $i$-th type of cosmetic, if she buys "Company A's product", Sonia gains $A_i$ happiness, and if she buys "Company B's product", Sonia gains $B_i$ happiness (each of these may be negative).
Here, among the $N$ types of cosmetics, Sonia wants to buy "Company A's product" for exactly $K$ types and "Company B's product" for exactly $N-K$ types.
Among the ways of buying cosmetics that satisfy Sonia's request, find one way of buying the $N$ types of cosmetics that maximizes the total happiness gained.
Constraints
- $1 \leq N \leq 2 \times 10^5$
- $0 \leq K \leq N$
- $|A_i|, |B_i| \leq 10^9$
- All inputs are integers
Input
The input is given from standard input in the following format.$N$ $K$ $A_1$ $\cdots$ $A_N$ $B_1$ $\cdots$ $B_N$
Output
The output consists of a string $S$ of $N$ characters. For the $i$-th type of cosmetic, set $S[i]=$A if buying Company A's product, and $S[i]=$B if buying Company B's product. Also, do not forget the newline.
If there are multiple ways of buying that maximize the total happiness gained, you may output any one of them.
Sample
Sample 1
Input
3 1 2 7 4 3 5 8
Output
BAB
- If she buys Company A's product for the $1$-st type of cosmetic and Company B's products for the remaining cosmetics, Sonia gains $2+5+8=15$ happiness.
- If she buys Company A's product for the $2$-nd type of cosmetic and Company B's products for the remaining cosmetics, Sonia gains $3+7+8=18$ happiness.
- If she buys Company A's product for the $3$-rd type of cosmetic and Company B's products for the remaining cosmetics, Sonia gains $3+5+4=12$ happiness.
BAB is correct.
Sample 2
Input
5 2 1 1 1 1 1 2 2 2 2 2
Output
ABBBA
Among the $5$ types of cosmetics, every way of buying $2$ types from Company A and $3$ types from Company B gains $8$ happiness.
Therefore, all such ways of buying are correct. That is, not only ABBBA but also BAABB and ABBAB are correct.
Sample 3
Input
6 3 -31 -41 -59 -26 -53 -59 -27 -18 -28 -18 -28 -46
Output
ABBABA
No matter how she buys, the happiness gained is negative. Why would Sonia go shopping like this?
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Kazun
tatyam