/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 6ms 532.0 KiB
#3 Accepted 10ms 576.0 KiB
#4 Accepted 8ms 568.0 KiB
#5 Accepted 13ms 532.0 KiB
#6 Accepted 15ms 700.0 KiB
#7 Accepted 5ms 532.0 KiB
#8 Accepted 6ms 744.0 KiB
#9 Accepted 17ms 1.277 MiB
#10 Accepted 17ms 1.277 MiB
#11 Accepted 6ms 788.0 KiB
#12 Accepted 18ms 1.82 MiB
#13 Accepted 8ms 1.277 MiB
#14 Accepted 5ms 788.0 KiB

Code

#include<bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

int32_t main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        ll n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        int conseq_one = 0, one = 0, ans_conseq = 0;
        vector<int> store;

        for (int i = 0; i < n; i++) {
            conseq_one = 0;

            while (s[i] == '1' && i < n) {
                conseq_one++;
                i++;
            }
            store.push_back(conseq_one);
            //ans_conseq = max(ans_conseq, conseq_one);
        }

        int arr_size = store.size();

        sort(store.rbegin(), store.rend());

        int ans = store[0];

        for (int i = 1; i < arr_size && i <= k; i++) {
            ans += store[i];
        }

        cout << ans << endl;




        /*      int other_ones = one - ans_conseq;
              int non_conseq = abs(one - ans_conseq);

              if (other_ones <= k) cout << non_conseq + other_ones << endl;
              else {
                  if (other_ones >= k) cout << ans_conseq + k << endl;
                  else cout << ans_conseq + other_ones << endl;
              }*/

    }

    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:24:53
Judged At
2025-02-17 15:24:53
Judged By
Score
100
Total Time
18ms
Peak Memory
1.82 MiB