mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-02-17 12:26:49 +00:00
C - Sum of Substrings
https://codeforces.com/contest/1691/submission/159034603
This commit is contained in:
parent
32a10dc611
commit
67b90577c5
43
Codeforces/1691/C/C.cpp
Normal file
43
Codeforces/1691/C/C.cpp
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user