/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Wrong Answer 43ms 532.0 KiB

Code

// Author: Shawn Das Shachin-->(shawn_das)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define OPTIMIZE_IO ios::sync_with_stdio(false); cin.tie(nullptr);

void solve(){
    int n,k;
    cin>>n>>k;
    string str;
    cin>>str;

    int max_count = 0, count = 0;
    vector<int> counts;
    for (auto it : str) {
        if (it == '1') {
            count++;
            max_count = max(max_count, count);
        } else {
            counts.push_back(count);
            count = 0;
        }
    }
    counts.push_back(count);
    rsrt(counts);
    for(auto it : counts){
        cout<<it<<" ";
    }
    cout<<endl;
    ll ans=0;
    for(int i=0; i<=k; i++){
        ans+=counts[i];
    }
    cout<<ans<<endl;
}
int main() {
    OPTIMIZE_IO;
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    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:19:29
Judged At
2025-02-17 15:19:29
Judged By
Score
0
Total Time
43ms
Peak Memory
532.0 KiB