Task Scheduling with Cooldown (greedy + counting)

VERY HARD · C · 5000ms

Between matches, players need rest between repeat appearances of the same role — Zayan must schedule to minimize the total match slots needed given this cooldown rule. Given N tasks (represented as letters) and a cooldown period K (the same task type must wait at least K units before repeating), print the minimum total time units needed to complete all tasks (idle slots allowed).

Input

Line1: N K. Line2: a string of N task letters.

Output

Minimum total time units.

Constraints

1 ≤ N ≤ 10^4, 0 ≤ K ≤ 100

Sample Input

6 2
AAABBB

Sample Output

8
main.c
Loading editor…

Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.

Task Scheduling with Cooldown (greedy + counting) · DIU ContestHub