0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-15 01:58:48 +00:00
OI-codes/Codeforces/1691/C/C.cpp

44 lines
818 B
C++
Raw Normal View History

#include <iostream>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
int t, n, k;
std::string s;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
cin >> n >> k >> s;
auto i = s.find_last_of('1');
if (i != std::string::npos && n - i - 1 <= k) {
k -= n - i - 1;
std::swap(s[n - 1], s[i]);
}
auto j = s.find_first_of('1');
if (j != n - 1) {
if (j != std::string::npos && j <= k) {
std::swap(s[0], s[j]);
k -= j;
}
}
int ans = 0;
for (int i = 1; i < s.size(); i++) {
ans += std::stoi(s.substr(i - 1, 2));
}
cout << ans << endl;
}
return 0;
}