Accepted
Code
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
int t, n, k;
cin >> t;
while (t--) {
cin >> n >> k;
string s;
cin >> s;
vector < int > v;
int c = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
c++;
}
else {
v.push_back(c);
c = 0;
}
}
if (c) {
v.push_back(c);
}
sort(rbegin(v),rend(v));
int res = 0;
for (int i = 0; i < min(k + 1, (int)v.size()); i++) {
res += v[i];
}
cout << res << "\n";
}
// your code goes here
}
Information
- Submit By
- Type
- Submission
- Problem
- P1159 Binary String
- Contest
- Brain Booster #8
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-02-17 15:57:24
- Judged At
- 2025-02-17 15:57:24
- Judged By
- Score
- 100
- Total Time
- 36ms
- Peak Memory
- 3.82 MiB