/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 6ms 588.0 KiB
#3 Accepted 10ms 540.0 KiB
#4 Accepted 5ms 540.0 KiB
#5 Accepted 4ms 540.0 KiB
#6 Accepted 4ms 796.0 KiB
#7 Accepted 2ms 540.0 KiB
#8 Accepted 2ms 704.0 KiB
#9 Accepted 5ms 1.285 MiB
#10 Accepted 5ms 1.285 MiB
#11 Accepted 2ms 796.0 KiB
#12 Accepted 2ms 796.0 KiB
#13 Accepted 4ms 1.781 MiB
#14 Accepted 2ms 840.0 KiB

Code

//! In The Name Of Allah

/*********************************************************************\
*!          |       *        |       | ___  | @                       |
*!          |      * *       |       |  |   |  @                      |
*!          |     *   *      |       |  |   |   @                     |
*!          |    *******     |-------|  |   |    @                    |
*! |*       |   *       *    |       |  |   |   @                     |
*! |        |  *         *   |       |  |   |  @                      |
*! |________| *           *  |       | ___  | @                       |
*!                                                                    |
*!  codeforces = __Jahid__Noob__                                      |
*!  mail =  [email protected]                                       |
*!  IIT,Jahangirnagar University(41)                                  |
*!                                                                    |
**********************************************************************/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define pb push_back
#define pob pop_back
#define make M
#define F first
#define S second
#define all(s) (s).begin(), (s).end()
#define rall(s) s.rbegin(), s.rend()
#define sz(x) (int)x.size()
#define mem(a, b) memset(a, b, sizeof(a))
#define log2(x) 31 - __builtin_clz(x)
#define getbit(n, i) (((n) & (1LL << (i))) != 0)
#define msb(x) 31 - __builtin_clz(x)
#define TxtIO                         \
    freopen("sample.in", "r", stdin); \
    freopen("sample.out", "w", stdout);
#define Fokinnir_moto_kaj_koris_na \
    ios_base::sync_with_stdio(0);  \
    cin.tie(0);                    \
    cout.tie(0);
#define py cout << "YES" << endl
#define pn cout << "NO" << endl
#define PI acos(-1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef tuple<int,int,int> tu;

// #define DEBUG
#define TEM template <class... T>
TEM istream& operator>>(istream& in, pair<T...>& p) { return in >> p.first >> p.second; }
TEM ostream& operator<<(ostream& out, const pair<T...>& p) { return out << '(' << p.first << ", " << p.second << ')'; }
#define def_in(cont) TEM istream& operator>>(istream& in, cont<T...>& A) { for (auto& a : A) in >> a; return in; }
#define def_out(cont) TEM ostream& operator<<(ostream& out, const cont<T...>& A) { int i = 0; auto it = A.begin(); while (it != A.end()) out << &" "[!i++] << *it++; return out; }
def_in(vector) def_in(deque) def_out(vector) def_out(deque) def_out(set) def_out(map) def_out(multiset)

TEM void c_in(T&... args) { ((cin >> args), ...); }
TEM void c_out(const T&... args) { int i = 0; ((cout << &" "[!i++] << args), ...) << '\n'; }
void c_out(bool b) { c_out(b ? "YES" : "NO"); }

#ifdef DEBUG
TEM void c_err(const T&... args) { int i = 0; ((cerr << &" "[!i++] << args), ...) << '\n'; }
#else
#define c_err(...)
#endif
#define dbg(args...) c_err(#args, '=', args)

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

/*
int p = 237,mod = 1000000289;
auto Goriber_function = [&] (int m) -> int{

};
*/
const ll oo = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 123;

void Goriber_solve()
{
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vi ar;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '1')cnt++;
        else{
            if(cnt > 0)ar.pb(cnt);
            cnt = 0;
        }
    }
    if(cnt > 0)ar.pb(cnt);
    sort(rall(ar));
    int ans = 0;
    for(int i = 0; i < min(sz(ar),k+1); i++){
        ans += ar[i];
    }
    cout << ans << endl;
}
signed main()
{

    Fokinnir_moto_kaj_koris_na
    int _ = 1,tc = 0;
    cin >> _;
    while (_--)
    {
        //cout<<"Case "<<++tc<<": ";
        Goriber_solve();
    }
}

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:46:22
Judged At
2025-02-17 14:46:22
Judged By
Score
100
Total Time
10ms
Peak Memory
1.781 MiB