#C11258. Maximize Decimal Value
Maximize Decimal Value
Maximize Decimal Value
You are given a binary sequence of length \(N\) and you are allowed to perform at most \(M\) bit flips. In each flip, you change a '0' to a '1'. Your task is to maximize the decimal value of the binary sequence by flipping some of the bits (always changing '0' to '1').
More formally, given integers \(N\) and \(M\) and a binary sequence \(s\) of length \(N\), you need to change at most \(M\) zeros present in \(s\) (from left to right) into ones so that the resulting binary number has the maximum possible value. It is guaranteed that \(0 \le M \le N\).
inputFormat
The input is read from standard input (stdin) as a single line containing three items separated by spaces:
- An integer \(N\), representing the length of the binary sequence.
- An integer \(M\), representing the maximum number of bit flips allowed.
- A string of length \(N\) representing the binary sequence (composed of characters '0' and '1').
outputFormat
Output a single integer which is the maximum possible decimal value of the binary sequence after performing at most \(M\) bit flips.
## sample5 1 10101
29