-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1691.cpp
More file actions
43 lines (39 loc) · 836 Bytes
/
1691.cpp
File metadata and controls
43 lines (39 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int a,b;cin>>a>>b;
string str; cin >> str;
int result = 0;
for (int i = 0; i < a; i++) if (str[i] == '1') result += 11;
for (int i = 0; i <= b; i++) {
int c = a-1-i;
if (c<0)break;
if (str[c] == '1') {
b-=i;
str[c]='0';
str[a-1]='1';
result-=10;
break;
}
}
for (int i = 0; i <= b; i++) {
if (i == a-1) break;
if (str[i] == '1') {
result-=1;
break;
}
}
cout << result;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int T = 1;
cin >> T;
while (T--) {
solve();
cout << '\n';
}
return 0;
}