/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define bug(a) cout << #a << " : " << a << endl;
bool cmp(pair<int,int> p1, pair<int,int> p2){
    return (p1.second < p2.second);
}

void solve()
{
    int n, k;   cin >> n >> k;
    string s;   cin >> s;

    if (n == k){
        cout << 0 << '\n';
        return;
    }

    stack<int> st;
    for(auto c : s){
        int x = c - '0';

        while ( !st.empty() and (st.top() < x ) and k) {
            st.pop();
            k--;
        }
        st.push(x);
    }

    while( k and !st.empty() ) {
        st.pop();
        k--;
    }


    string ans = "";
    while( !st.empty() ) {
        ans.push_back(st.top() + '0');
        st.pop();
    }

    reverse( ans.begin(), ans.end() );
    cout << ans << '\n';
    //return ans;


}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1, tc = 0;
    cin >> t;

    while(t--){
    	//cout << "Case " << ++tc << ": ";
    	solve();
    } 
}


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 10:30:15
Judged At
2024-10-30 10:30:15
Judged By
Score
100
Total Time
1ms
Peak Memory
540.0 KiB