#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 nn 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 kk is also known. Among every kk consecutive hours, there should be at least msm_{s} hours when the cat is sleeping, and at least mem_{e} hours when the cat is eating. So, there are exactly nk+1n − k + 1 segments of kk hours for which this condition must be satisfied.

Find the maximum total amount of delight the cat can get during the next nn hours.

输入格式

The first line of the input contains four integers n,k,ms,n , k , m_{s}, and me(1kn1000m_{e} (1 \le k \le n \le 1000 ; 0ms,mek0 \le m_{s}, m_{e} \le k ; ms+mek)m_{s} + m_{e} \le k) -- 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 kk consecutive hours, respectively.

The second line contains nn integers s1,s2,s_{1}, s_{2}, . . . , sn(0si109s_{n} (0 \le s_{i } \le 10^{9} ) -- the amount of delight the cat gets when it is sleeping during the first, the second, , \cdots , the n-th hour.

The third line contains nn integers e1,e2,e_{1}, e_{2}, . . . , en(0ei109e_{n} (0 \le e_{i} \le 10^{9} ) -- the amount of delight the cat gets when it is eating during the first, the second, , \cdots , 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 nn hours.

In the second line, output a string of length nn consisting of characters S and E. The i-th character of this string should correspond to whether the cat should sleep (S)(`S`) or eat (E)(`E`) in the i-th hour to get the maximum total amount of delight out of these nn hours.

题目大意

一只猫猫在连续的 nn 个小时中可以进行睡觉或进食两种动作。一个小时内只能选择其中一种进行。

现在你知道这只猫在接下来的这 nn 个小时中每第 ii 个小时睡觉或进食分别获得的快乐值 sis_ieie_i

但是对于每一个连续的 kk 个小时,这只猫必须满足在这 kk 个小时内至少有 mem_e 个小时的进食时间和 msm_s 个小时的睡觉时间。也就是说在这 nn 个小时中的 nk+1n-k+1kk 长连续区间必须满足睡觉时间 ms\geq m_s ,进食时间 me\geq m_e

现在小猫想知道自己这 nn 个小时最多能获得多少快乐值以及相对应的方案。

输入:

第一行分别输入 n,k,ms,men,k,m_s,m_e

第二行输入 nn 个数字 s1,s2,,sns_1,s_2,\dots, s_n 分别代表每个小时如果睡觉可以获得的快乐值。

第三行输入 nn 个数字 e1,e2,,ene_1,e_2,\dots,e_n 分别代表每个小时如果进食可以获得的快乐值。

输出:

第一行输出可以获得的最大快乐值。

第二行输出一个合法方案nn 个字符表示每个小时进行的动作。第 ii 个字符用 S 表示第 ii 个小时在睡觉,或用 E 表示第 ii 个小时在进食。

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.