Wrong Answer
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll testcases;
cin >> testcases;
while (testcases--) {
ll n , k;
cin >> n >> k;
string s;
cin >> s;
char num = s[0];
ll i = 0 , cnt = 0;
vector<ll> arr;
while(i < n){
if(s[i] == num){
cnt++;
}
else{
if(cnt && num == '1') arr.push_back(cnt);
num = s[i];
cnt = 0;
continue;
}
i++;
}
if(cnt && num == '1') arr.push_back(cnt);
k++;
if(k >= arr.size()){
ll ans = 0;
for(auto p : arr) ans += p;
cout << ans << "\n";
continue;
}
ll ans = 0 , curr = 0;
for(ll i = 0 ; i < arr.size() ; i++){
curr += arr[i];
if(i - k >= 0) curr -= arr[i - k];
ans = max(ans , curr);
}
cout << ans << "\n";
}
return 0;
}
// Author : Raj (raj_singh35)
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:05:32
- Judged At
- 2025-02-17 15:05:32
- Judged By
- Score
- 0
- Total Time
- 7ms
- Peak Memory
- 816.0 KiB