/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 6ms 440.0 KiB
#3 Accepted 8ms 532.0 KiB
#4 Accepted 5ms 532.0 KiB
#5 Accepted 6ms 532.0 KiB
#6 Accepted 8ms 808.0 KiB
#7 Accepted 292ms 672.0 KiB
#8 Accepted 2ms 692.0 KiB
#9 Accepted 5ms 1.773 MiB
#10 Accepted 9ms 1.82 MiB
#11 Accepted 3ms 788.0 KiB
#12 Accepted 4ms 788.0 KiB
#13 Accepted 15ms 1.848 MiB
#14 Accepted 7ms 800.0 KiB

Code

#define ll             long long int
#define vll            vector<ll>
#define vss            vector<string>
#define vcc            vector<cc>
#define pll            pair<ll,ll>
#define mll            map<ll,ll>
#define msl            map<string,ll>
#define mcl            map<char,ll>
#define vpll           vector<pll>
#define sll            set<ll>
#define skip           continue
#define pb             push_back
#define ppb            pop_back
#define yes            cout<<"Yes"<<endl
#define no             cout<<"No"<<endl
#define nai            cout<<-1<<endl
#define vprint(v)      for(auto x:v)cout<<x<<" ";cout<<endl
#define nl             <<'\n'
#define sp             <<" "<<
#define spn            <<" "
#define fst            first
#define sec            second
#define loop(i, a, b)  for(i = a; i <= b; i++)
#define loop2(i, b, a) for(i = b; i >= a; i--)
#define MOD            1000000007
#define bit1(x)        __builtin_popcount(x)
#define vsob(x)        x.begin(), x.end()
#define vsort(x)       sort(vsob(x))
#define vreverse(x)    reverse(vsob(x))
#define asob(x)        x,x+n
#define asort(x)       sort(asob(x))
#define areverse(x)    reverse(asob(x))
#define vmax(a)        *max_element(vsob(a))
#define amax(a)        *max_element(asob(a))
#define vmin(a)        *min_element(vsob(a))
#define amin(a)        *min_element(asob(a))
#define vsum(a)        accumulate(a.begin(), a.end(), 0);
#define asum(a)        accumulate(a, a+n, 0);
#define lower(x,a)     lower_bound(x.begin(), x.end(), a)-x.begin()
#define upper(x,a)     upper_bound(x.begin(), x.end(), a)-x.begin()
#define takevector     vector<ll>v(n);for(i=0;i<n;i++)cin>>v[i];
#define takevector1    vector<ll>v(n+1);for(i=1;i<=n;i++)cin>>v[i];
#define takearray      ll arr[n];for(i=0;i<n;i++)cin>>arr[i];
#define takearray1     ll arr[n+1];for(i=1;i<=n;i++)cin>>arr[i];
#define minpq          priority_queue <ll, vector<ll>, greater<ll>>
#define inf            INT_MAX
#define gcd __gcd
#define fio ifstream fin; fin.open("input.txt"); ofstream fout; fout.open("output.txt");
#define ioclose fin.close(); fout.close();
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> //s.order_of_key  , *s.find_by_order
#include <bits/stdc++.h>
using namespace std;
ll lcm(ll a, ll b){
    return ((a*b)/gcd(a,b));
}
ll modPow(ll a , ll n){ ll res = 1;while(n){if(n&1)res = (res * a) % MOD;a = (a * a) % MOD; n >>= 1;}return res;}
ll binPow(ll a , ll n){ ll res = 1;while(n){if(n&1)res = (res * a);a = (a * a) ; n >>= 1;}return res;}


void solve(){
    ll n,m,q,k=10,i,j,l,w,x=-1,y=0,x2,y2,x1,y1,x3,y3,a,b,c=1,d,e,sum=0,mx=LONG_LONG_MIN,ans=0,gc=1,i1,j1,i2,j2,ind,val;
    cin>>n>>k;
    string s;
    priority_queue<ll>p;
    cin>>s;
    i=0;
    while(s[i]=='0')i++;
    c=0;
    for(;i<n;i++){
        if(s[i]=='1'){
            c++;
        }
        else{
            p.push(c);
            c=0;
        }
    }
    if(c!=0)p.push(c);
    if(!p.empty()){
        y+=p.top();
        p.pop();
    }
    while(k--){
        if(!p.empty()){
            y+=p.top();
            p.pop();
        }
    }
    cout<<y nl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t1=1,j=0;
    cin>>t1;
    while(t1--){
        j++;
        //cout<<"Case "<<j<<": ";
        solve();
    }
    return 0;
}






// sum = sum/d . In modular inverse it will be sum = (sum*modPow(d,MOD-2))%MOD;

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:09:41
Judged At
2025-02-17 15:09:41
Judged By
Score
100
Total Time
292ms
Peak Memory
1.848 MiB