/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 14ms 572.0 KiB
#3 Wrong Answer 16ms 808.0 KiB

Code

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define f first 
#define s second 
using namespace std;

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--){
        ll n, k;
        string s;
        cin >> n >> k >> s;
        vector<ll> a;
        while (!s.empty()){
          while (!s.empty() && s.back() == '0') s.pop_back();
          int c = 0;
          while (!s.empty() && s.back() == '1') c++, s.pop_back();
          if (c) a.push_back(c);
        }
        if (a.empty()){
          cout << 0 << endl;
          continue;
        }
        sort(a.rbegin(), a.rend());
        ll cur = a[0];
        ll m = a.size();
        for (int i = 1; i <= min(m, k); i++){
          cur += a[i];
        }
        cout << cur << endl;
    }
}

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:53:19
Judged At
2025-02-17 14:53:19
Judged By
Score
0
Total Time
16ms
Peak Memory
808.0 KiB