/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB

Code

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

int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        string str;
        cin>>str;

        int ok=k;
        vector<char>vec;
        int pre=0;
        for(int i=0;i<n;i++){
            int mx=0, d=i, j=i, s=0;
            for(j=i,s=0;s<=k && j<n;s++,j++){
                int num=str[j]-'0';
                if(mx<num){
                    d=j;
                    mx=num;
                }
            }
            vec.push_back(str[d]);
            i=d;
            k-=d-pre;
            pre=d+1;
            //cout<<k<<" "<<pre<<endl;
        }

        if(vec.empty()) cout<<"0"<<endl;
        else{
            if(vec.size()>n-ok){
                int sz=vec.size()-(n-ok);
                while(sz--){
                    vec.pop_back();
                }
            }

            if(vec.empty()) cout<<"0"<<endl;
            else{
                for(int i=0;i<vec.size();i++){
                    cout<<vec[i];
                }
                cout<<endl;
            }
        }
    }
}

Information

Submit By
Type
Submission
Problem
P1006 Remove K Digits
Contest
Sylhet ICPC 2024 Collaborative Challenge: Episode 2
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-30 09:58:06
Judged At
2024-11-11 02:35:13
Judged By
Score
100
Total Time
2ms
Peak Memory
320.0 KiB