Third Group Exam
InterviewTime limit1sMemory limit512 MB
Given per-block theory grades x_i and practice grades y_i, pick at least a theory blocks and at least b practice blocks to maximize the total grade, and print the choice.
Statement
One teacher came up with a new format for an exam. The exam consists of blocks, one for each topic. A student receives a grade for the -th block, for every from to , and all grades are independent. Each grade is an integer from to , inclusive.
For each block, a student chooses one way to earn the grade: answer a theoretical question or solve a practical problem. The exam is passed successfully if at least blocks were graded by answering a theoretical question and at least blocks were graded by solving a practical problem. If the exam is passed, the final grade is the sum of the grades for all blocks: .
Ilya is about to take the exam. For block , answering the theoretical question gives him a grade of , and solving the practical problem gives him a grade of . Help him decide which blocks (at least of them) he should answer by theory and which blocks (at least of them) he should solve by practice, so that his total exam score is as large as possible.
Input
The first line contains three integers , and , the total number of topics, the minimum number of blocks to pass by theory, and the minimum number of blocks to pass by practice (; ). It is guaranteed that .
The second line contains integers , the grades for answering the theoretical questions ().
The third line contains integers , the grades for solving the practical problems ().
Output
The first line must contain a single integer , the maximum total grade Ilya can get.
The second line must contain space-separated characters, where the -th character is T if Ilya should answer the theoretical question for block , and P if he should solve the practical problem. At least characters must be T, and at least characters must be P.