문제
Note: The time limit for this problem is 3s, 1.5x the default.
Bessie has a string of length () consisting solely of the characters M and O. For each position of the string, there is a cost to change the character at that position to the other character ().
Bessie thinks the string will look better if it contains more moos of length (). A moo of length is an M followed by Os.
For each positive integer from to inclusive, compute the minimum cost to change the string to contain at least substrings equal to a moo of length .
입력
The first line contains and .
The next line contains Bessie's length- string, consisting solely of Ms and Os.
The next line contains space-separated integers .
출력
Output lines, the answer for each in increasing order.
예제 입력 1
1 4
MOOO
10 20 30 40
예제 출력 1
0
20
50
90
예제 입력 2
3 4
OOOO
50 40 30 20
예제 출력 2
40
예제 입력 3
2 20
OOOMOMOOOMOOOMMMOMOO
44743602 39649528 94028117 50811780 97338107 30426846 94909807 22669835 78498782 18004278 16633124 24711234 90542888 88490759 12851185 74589289 54413775 21184626 97688928 10497142
예제 출력 3
0
0
0
0
0
12851185
35521020
60232254
99881782
952304708
예제 입력 4
3 20
OOOMOMOOOMOOOMMMOMOO
44743602 39649528 94028117 50811780 97338107 30426846 94909807 22669835 78498782 18004278 16633124 24711234 90542888 88490759 12851185 74589289 54413775 21184626 97688928 10497142
예제 출력 4
0
0
0
44743602
119332891
207066974
점수
Input 5: Input 6: Inputs 7-10: Inputs 11-18:
코드를 제출하려면 로그인이 필요합니다.
로그인