#P9051. [PA 2021] Wystawa

    ID: 9755 远端评测题 6000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP贪心二分平衡树2021Special JudgePA(波兰)

[PA 2021] Wystawa

Problem Description

You are given two sequences aa and bb of length nn.

You need to construct a sequence cc as follows:

  • Choose kk indices ii and set ciaic_i \leftarrow a_i.
  • For all other ii, set cibic_i \leftarrow b_i.

Find the minimum possible value of the maximum subarray sum of sequence cc, and output one valid construction.

Input Format

The first line contains two integers n,kn, k.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n.

The third line contains nn integers b1,b2,,bnb_1, b_2, \cdots, b_n.

Output Format

The first line contains one integer, the minimum possible value of the maximum subarray sum of sequence cc.

The second line contains a string ss of length nn. If ciaic_i \leftarrow a_i, then si=As_i = \text{A}; otherwise, si=Bs_i = \text{B}.

If there are multiple solutions, output any one of them.

6 2
-1 7 0 2 -5 0
3 1 4 -3 -3 12
4
BBABBA
3 2
-1 -4 -1
-4 -2 -1
0
AAB

Hint

For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 0kn0 \leq k \leq n, and 109ai,bi109-10^9 \leq a_i, b_i \leq 10^9.

Translated by ChatGPT 5