luogu#P6967. [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.
题目大意
一只猫猫在连续的 个小时中可以进行睡觉或进食两种动作。一个小时内只能选择其中一种进行。
现在你知道这只猫在接下来的这 个小时中每第 个小时睡觉或进食分别获得的快乐值 和 。
但是对于每一个连续的 个小时,这只猫必须满足在这 个小时内至少有 个小时的进食时间和 个小时的睡觉时间。也就是说在这 个小时中的 个 长连续区间必须满足睡觉时间 ,进食时间 。
现在小猫想知道自己这 个小时最多能获得多少快乐值以及相对应的方案。
输入:
第一行分别输入 。
第二行输入 个数字 分别代表每个小时如果睡觉可以获得的快乐值。
第三行输入 个数字 分别代表每个小时如果进食可以获得的快乐值。
输出:
第一行输出可以获得的最大快乐值。
第二行输出一个合法方案, 个字符表示每个小时进行的动作。第 个字符用 S
表示第 个小时在睡觉,或用 E
表示第 个小时在进食。
10 4 1 2
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
69
EEESESEESS
提示
Time limit: 2 s, Memory limit: 512 MB.