Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
850 B
1
Indexable
#include <bits/stdc++.h>
#define endl '\n'
#define maxn 100005
#define For(i,a,b) for (int i = a; i <= b; i++)

using namespace std;
char st[maxn];
int top = 0, k;
string s;

void push(char x) {
    top++;
    st[top] = x;
}

void pop() {
    top--;
    k--;
}

void inp() {
    cin >> s >> k;
}

void solve() {
    if (k >= s.size()) {
        cout << "" << endl;
        return;
    }

    for (int i = 0; i < s.size(); i++)
    {
         while(top != 0 && k > 0 && st[top] > s[i]) pop();
         push(s[i]);
    }

    while (k > 0) pop();

    For(i, 1, top) {
        cout << st[i];
    }
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("bai1.inp","r")){
        freopen("bai1.inp","r",stdin);
    }
    inp();
    solve();
    return 0;
}
Leave a Comment