#P4842. [Neerc2016]Delight for a Cat
[Neerc2016]Delight for a Cat
题目描述
A cat is going on an adventure.
Each hour, the cat can be either sleeping or eating. The cat cannot be doing both actions at the same hour, and the cat is doing exactly one of these actions for the whole hour.
For each of the next hours, the amount of delight the cat is getting if it is sleeping or eating during that hour is known. These amounts can be different for each hour.
An integer time period is also known. Among every consecutive hours, there should be at least hours when the cat is sleeping, and at least hours when the cat is eating. So, there are exactly segments of hours for which this condition must be satisfied.
Find the maximum total amount of delight the cat can get during the next hours.
输入格式
The first line of the input contains four integers and ; ; -- the number of upcoming hours, the length of the period (in hours), and the minimum number of hours the cat should be sleeping and eating out of every consecutive hours, respectively.
The second line contains integers . . . , ) -- the amount of delight the cat gets when it is sleeping during the first, the second, the n-th hour.
The third line contains integers . . . , ) -- the amount of delight the cat gets when it is eating during the first, the second, the n-th hour.
输出格式
In the first line, output a single integer -- the maximum total amount of delight the cat can get during the next hours.
In the second line, output a string of length consisting of characters S
and E
. The i-th character of this string should correspond to whether the cat should sleep or eat in the i-th hour to get the maximum total amount of delight out of these hours.
样例 #1
样例输入 #1
10 4 1 2
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
样例输出 #1
69
EEESESEESS
提示
Time limit: 2 s, Memory limit: 512 MB.