#GD0000206. Tổng các xâu con độ dài hai (Sum of Substrings)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng các xâu con độ dài hai (Sum of Substrings)
Sum of Substrings
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a binary string . Each adjacent pair represents a two-digit decimal number ; a leading zero is allowed. Define
For example, 1011 gives 10, 01, 11 and hence .
One operation swaps two adjacent characters. At most operations may be performed; you do not have to use them all. Find the smallest possible value of .
Input
- The first line contains integers and : the string length and the maximum allowed number of swaps.
- The second line contains a binary string of exactly characters.
Output
Print one integer: the minimum possible value of after no more than adjacent swaps.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5 2
00110
Output
12
Explanation
For 00110, adjacent pairs give . Swapping the last 1 and 0 produces 00101 after one allowed swap. Its pairs are 00, 01, 10, 01, whose sum is . No arrangement reachable with at most two swaps yields a smaller sum, so the output is 12.