루미 알고리즘

#1568골드Squash

PO 2023 온라인 예선코딩출제 Fredrik Hernqist, Johan Sannemo영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

Göran has started playing squash with his friends. He is very dedicated and plays N matches per day. Göran's goal is, of course, to win as many matches and lose as few matches as possible. His satisfaction after a day of playing squash is equal to the number of matches he won minus the number of matches he lost.

In addition to getting better at squash and winning more matches, Göran has an extra trick to increase his satisfaction: he claims that he only played seriously during K different series of consecutive matches. Only these matches count in the calculation of his satisfaction. Göran always chooses these K match series to maximize his satisfaction.

A match series always consists of all matches between the i-th and the j-th match for some chosen i and j, but Göran can let one (or all!) match series be empty (e.g., maybe he took a very serious water break instead). The consecutive match series he chooses must not overlap, i.e., each match played can be part of at most one chosen match series.

Given the match history for a day, what will Göran's satisfaction be if he chooses the match series optimally?

Input

The first line of input contains the integer N and K (1 ≤ K ≤ N ≤ 1000), the number of matches an the number of serious matches.

The following line contains a string with N characters, the results of the matches that Göran played. The i:th of these characters is V if Göran won the i:th match, and F if he lost it.

Output

Print an integer: the maximum satisfaction that Göran can achieve.

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

GroupPointsConstraints
110K = 1
220K = 2
330K = 3
440No additional constraints.

예제

예제 1

입력
5 1
VVFVV
출력
3

예제 2

입력
5 2
VVFVV
출력
4

예제 3

입력
19 3
VVFFVFVVVFVVVFFFFVV
출력
9

예제 4

입력
1 1
F
출력
0

출처 표기

출처: Programmeringsolympiaden 2023년 온라인 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.