0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 13:18:46 +00:00

C - Sum of Substrings

https://codeforces.com/contest/1691/submission/159034603
This commit is contained in:
Baoshuo Ren 2022-05-31 23:23:19 +08:00
parent 32a10dc611
commit 67b90577c5
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

43
Codeforces/1691/C/C.cpp Normal file
View File

@ -0,0 +1,43 @@
#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;
}