There is a binary string S of length N. In one operation, you choose an index i (1≤i≤N) and flip Si. More formally:
Define the inversion count of a binary string as the number of pairs (i,j) such that 1≤i<j≤N, Si=1 and Sj=0.
Find the minimum inversion count of S after performing at most K operations.
N K S1S2…SN
An integer representing the minimum inversion count of Safter performing at most Koperations.
10 2 1111010001
9
3 3 011
0
3 1 100
0
In the first sample, we use 2 operations with i=8 then i=9 so that S becomes 1111010111. The inversion count here is 9 and we can show that it is the minimum inversion count.
In the second sample, we use 2 operations with i=3 then i=3 so that S becomes 011. The inversion count here is 0 and it is clearly the minimum inversion count.
Subtask | Score |
---|---|
1 | 100 |