#P5262. [ROI2007 / JSOI2013] 体育课

[ROI2007 / JSOI2013] 体育课

Problem Description

There are NN students in the PE class, with student IDs from 11 to NN. JYY’s PE teacher KFC has a special way to arrange the line:

  • KFC first makes the NN students stand in a row from left to right in increasing order of student ID. Then, starting from the far left of the line (in front of the first student), KFC walks to the right until reaching the (N1)(N-1)-th student.
  • Next, KFC returns to the first student and starts walking to the right again. In total, KFC walks N1N-1 times.
  • Each time when KFC reaches the ii-th student, KFC compares the heights of the ii-th and (i+1)(i+1)-th students. If the student on the left (the ii-th) is taller than the student on the right (the (i+1)(i+1)-th), KFC swaps their positions in the line.

After all N1N-1 walks are finished, KFC will choose some students on the far right of the line to move desks. Naturally, JYY wants to stand as far to the left as possible to increase his chances to play soccer.

In addition, JYY has a special trick: when KFC is about to walk up to him, JYY can squat down to tie his shoelaces. If JYY squats down to tie his shoelaces, then during that walk, the easygoing teacher KFC will not make JYY compare heights with adjacent students, and of course will not make JYY swap positions with adjacent students (only JYY is smart enough to squat down; all other students will honestly let KFC compare heights).

Squatting down to tie shoelaces costs a lot of energy. To save energy for playing soccer, JYY can squat at most KK times.

JYY wants to know what squatting strategy can make him stand as far to the left as possible in the line. Use a string of length N1N-1 to represent a strategy: if the ii-th character of the string is +, it means JYY squats down to tie his shoelaces during the ii-th walk; if it is -, it means JYY will honestly compare heights.

Input Format

The first line contains three integers N,P,KN, P, K, representing the number of students, JYY’s student ID, and the maximum number of times JYY can squat.

The second line contains NN integers, where the ii-th integer is hih_i, the height of the student with ID ii.

Output Format

The first line contains one positive integer, the leftmost position JYY can reach under the best strategy.

The second line contains a string of length N1N-1, representing the best strategy. If there are multiple best strategies, JYY wants the lexicographically largest one.

10 7 7
8 3 5 4 5 7 4 2 1 3
3
----+++++

Hint

Constraints: 1PN1051\le P\le N\le 10^5, 0KN10\le K\le N-1, 1hi1091\le h_i\le 10^9.

Translated by ChatGPT 5