/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 7ms 532.0 KiB
#3 Wrong Answer 10ms 532.0 KiB

Code

#include <bits/stdc++.h>

#define nl              cout<<'\n';
#define space           cout<<' ';
#define print(s)        cout<<s;

#define ll              long long
#define all(x)          (x).begin(), (x).end()
#define Point(x,y)      setprecision((y))<<fixed<<(x)

#define yes             cout<<"YES\n";
#define no              cout<<"NO\n";

#define Fast            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(x)          cout<<"line " << __LINE__ << " says: " << #x << " = " << x << "\n";

#define printarry(a)    for(auto it : a) cout<<it<<' ';
#define put_array(x,n)  for (int i = 0; i < n; ++i) cin >> x[i];




using namespace std;





//-----------------------------------------------------------------------------------------------------------------------------------
//                                                  PRACTICE AND LEARN                                                                                         
//-----------------------------------------------------------------------------------------------------------------------------------


void test_case()
{
       int n,k;
       cin >>  n >> k;

       string s; 
       cin >> s;

        std::vector<int> v;

        int cnt = 0;

       for (int i = 0; i < n ; ++i)
       {
           if(s[i]=='1')
           {
                cnt++;
           }
           else
           {
                v.push_back(cnt);
                cnt=0;
           }
       }
        
        v.push_back(cnt);

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


       long long ans =  v[0];

       int point = 1;

       for (int i = 1; i <= k && point < n; ++i)
       {
           ans += v[point];
           point++;
       }

       cout << ans ;



      

    



    nl
    return;

}




int32_t main()
{
    Fast;

#ifdef NAYEEM

    int start_time = clock();
    int end_time = clock();
    printf("Time = %.4f\n", (end_time - start_time + 0.0) / CLOCKS_PER_SEC);
    
#endif

    int test_number = 1;
    cin >> test_number;

    while (test_number--)
    {
      
        test_case();

    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1159 Binary String
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 17:28:23
Judged At
2025-02-17 17:28:23
Judged By
Score
0
Total Time
10ms
Peak Memory
532.0 KiB