/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Accepted 10ms 588.0 KiB
#3 Accepted 12ms 580.0 KiB
#4 Accepted 7ms 328.0 KiB
#5 Accepted 6ms 576.0 KiB
#6 Accepted 7ms 676.0 KiB
#7 Accepted 3ms 540.0 KiB
#8 Accepted 3ms 704.0 KiB
#9 Accepted 5ms 1.121 MiB
#10 Accepted 7ms 972.0 KiB
#11 Accepted 3ms 748.0 KiB
#12 Accepted 3ms 840.0 KiB
#13 Accepted 6ms 1.238 MiB
#14 Accepted 3ms 796.0 KiB

Code

#include <bits/stdc++.h>     //   All praise is due to Allah alone, and peace and blessings be
using namespace std;         //         upon him, after whom there is no other Prophet.


int32_t main() {
    cin.tie(0)->sync_with_stdio(false);

    function<void()> Test_Case = [&]() {
        int n, k; cin >> n >> k;
        string s; cin >> s;
        priority_queue<int> p;
        for(int i = 0, j, cnt; i < n; i = j) {
            cnt = 1, j = i + 1;
            for( ; j < n; j++) {
                if(s[i] == s[j]) {cnt++;}
                else break;
            }
            if(s[i] == '1') {
                p.push(cnt);
            }
        }
        int ans = 0;
        while(p.size() and k >= 0) {
            ans += p.top(); p.pop();
            k--;
        }
        cout << ans << '\n';
    };

    int32_t Case = 1;    cin >> Case;
    for (int T = 1; T <= Case; T++) {
        Test_Case();
    }
    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:10:11
Judged At
2025-02-17 16:10:11
Judged By
Score
100
Total Time
12ms
Peak Memory
1.238 MiB