Accepted
Code
#include <bits/stdc++.h>
using namespace std;
void solve(int cs) {
int n, k;
cin >> n >> k;
multiset<int> S;
string s; cin >> s;
int ones = 0;
for (auto &c : s) {
if (c == '1') ones += 1;
else if (ones) S.insert(ones), ones = 0;
}
if (ones) S.insert(ones);
int ans = 0;
while (k >= 0 && S.size() > 0) {
ans += *S.rbegin();
S.erase(--S.end());
--k;
}
cout << ans << "\n";
}
int32_t main() {
ios::sync_with_stdio(!cin.tie(0));
int t = 1;
cin >> t;
for (int i = 1; i <= t; ++i) {
solve(i);
}
return 0;
}
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 14:41:09
- Judged At
- 2025-02-17 14:41:09
- Judged By
- Score
- 100
- Total Time
- 26ms
- Peak Memory
- 5.203 MiB