There is a binary string \(S\) of length \(N\). In one operation, you choose an index \(i\) (\(1 \le i \le N\)) and flip \(S_i\). More formally:
Define the inversion count of a binary string as the number of pairs \((i,j)\) such that \(1 \le i < j \le N\), \(S_i=\texttt{1}\) and \(S_j=\texttt{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 \(S\)after performing at most \(K\)operations.
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 \(\texttt{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 \(\texttt{011}\). The inversion count here is \(0\) and it is clearly the minimum inversion count.
Subtask | Score |
---|---|
1 | 100 |