Wrong Answer
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
bool comp(pair<int,int>a, pair<int,int>b){
return a.first > b.first;
}
void tc(){
int t;
cin >> t;
while (t--){
int n,k;
cin >> n >> k;
string s;
cin >> s;
vector<int> v;
int ans = 0;
for(int i = 0; i < n; i++){
if(s[i] == '1'){
++ans;
}
else{
if(ans != 0){
v.push_back(ans);
ans = 0;
}
}
}
if(ans != 0){
v.push_back(ans);
ans = 0;
}
if(v.size() == 0){
cout << 0 << endl;
continue;
}
sort(v.begin(),v.end());
int ok = v[v.size()-1];
v.pop_back();
int sz = v.size();
if(k <= sz){
sz = k;
}
for(int i = 0; i < sz; i++){
ok += v[i];
}
cout << ok << endl;
v.clear();
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
tc();
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 16:00:26
- Judged At
- 2025-02-17 16:00:26
- Judged By
- Score
- 0
- Total Time
- 7ms
- Peak Memory
- 532.0 KiB