/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error 1ms 532.0 KiB

Code

// Author: Gourav Preet Gupta
// Language: C++

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define float long double
#define yes  cout << "YES" << endl;
#define no  cout << "NO" << endl;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define PI 3.141592653589793
#define Mod 1000000007

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef priority_queue<ll> pq;
typedef priority_queue<pair<ll,ll> > pqp;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

/*
****************************************LOVE YOU MAA***************************************************
**********************************FAMILY ABOVE ALL*****************************************************
**************************************GIVE ME SOME SUNSHINE , GIVE ME SOME RAIN************************
******************************GIVE ME ANOTHER CHANCE , I WANNA GROW UP ONCE AGAIN**********************
**************************************YE DIL MAANGE MORE***********************************************
**************************SHAURYAM DAKSHAM YUDDHE,BALIDAAN PARAM DHARMA********************************
*/

// Never Stop Trying.
// Trying to be Better than Myself.
 
// while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }

//Remember,mazaa journey mein jyaada hai,manzil main utna nahi....

const int N=1e5+5;

void solve()
{
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    stack<char> st;
    ll i=0ll;
    while(i<n && k)
    {
        if(st.empty())
        {
            st.push(s[i]);
        }
        else 
        {
            while(st.top()<s[i] && k && !st.empty())
            {
                st.pop();
                k--;
            }
            st.push(s[i]);
        }
        i++;
    }
    while(i<n)
    {
        st.push(s[i]);
        i++;
    }
    while(k--)
    {
        st.pop();
    }
    string ans = "";
    while(!st.empty())
    {
        ans+=st.top();
        st.pop();
    }
    reverse(all(ans));
    if(sz(ans)==0ll)
    cout<<"0"<<endl;
    else
    cout<<ans<<endl;
}

int main()
{    
    IOS;
    
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1006 Remove K Digits
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 10:40:42
Judged At
2025-01-02 10:40:42
Judged By
Score
0
Total Time
1ms
Peak Memory
532.0 KiB