/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 348.0 KiB
#2 Wrong Answer 6ms 580.0 KiB
#3 Wrong Answer 7ms 532.0 KiB

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());

        // for(int i = 0; i < v.size(); i++){
        //     cout << v[i] << " ";
        // }

        // int ok = v[v.size()-1];

        // v.pop_back();

        int ok = 0;

        for(int i = 0; i <= k;i++){
            ok += v[v.size()-1-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 15:46:37
Judged At
2025-02-17 15:46:37
Judged By
Score
0
Total Time
7ms
Peak Memory
580.0 KiB