/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Runtime Error 2ms 540.0 KiB
#3 Runtime Error 2ms 796.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set1 = tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update>;
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define PI 2.0 * acos(0.0)
#define Dpos(n) fixed << setprecision(n)
#define endl '\n'

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 1;

void solve()
{
    string s;
    ll n, k, c = 0, i;
    cin >> n >> k >> s;
    vl v1;
    for (auto it : s)
    {
        if (it == '0')
        {
            if (c)
                v1.push_back(c);
            c = 0;
        }
        else
        {
            c++;
        }
    }
    if (c)
        v1.push_back(c);
    sort(v1.rbegin(), v1.rend());
    ll ans = 0;
    for (i = 0; i <= k && i < n; i++)
    {
        ans += v1[i];
    }
    cout << ans << '\n';
}
int main()
{
    op() int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++)
    {
        // cout << "Case " << t << ": ";
        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:51:08
Judged At
2025-02-17 14:51:08
Judged By
Score
0
Total Time
2ms
Peak Memory
796.0 KiB