/ SeriousOJ /

Record Detail

Accepted


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

Code

#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
using namespace std;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
typedef long double lld;
const int MK=60;
const ll MOD=1000000007;

void solve(){
    int t;
    cin>>t;
    while(t--){
        lli n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        if(k==n){
            cout<<"0"<<nline;
            continue;
        }
        stack<char>st;
        for(int i=0;i<n;i++){
            while(!st.empty() && st.top()<s[i]&&k>0){
                st.pop();
                k--;
            }
            st.push(s[i]);
        }
        string temp="";
        while(k>0 &&!st.empty()){
            st.pop();
            k--;
        }
        while(!st.empty()){
            temp+=st.top();
            st.pop();
        }
        reverse(all(temp));
        cout<<(temp.empty()?"0":temp)<<nline;

    }

}

int main(){
    fastio();
    solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1006 Remove K Digits
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-04 06:29:15
Judged At
2024-11-11 02:33:50
Judged By
Score
100
Total Time
2ms
Peak Memory
332.0 KiB