/ SeriousOJ /

Record Detail

Accepted


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

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using minheap = priority_queue<long long, vector<long long>, greater<long long>>;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

#define ll long long
#define ld long double
#define MOD 1000000007
#define pie 2*(acos(0.0))
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define endl '\n'
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define print(v) for(auto e:v) cout<<e<<" "; cout<<endl;
#define printp(v) for(auto e:v) cout<<e.first<<" "<<e.second<<endl;
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define life_is_a_race ios::sync_with_stdio(false); cin.tie(nullptr);

void solve(int tc)
{
    //cout<<"Case "<<tc<<": ";
    int n,k; cin >> n >> k;
    string s; cin >>s;
    int a[n]={0};
    int cnt = 0;

    for(char c='0'; c<='9'; c++)
    {
        for(int i=0;i<n;i++)
        {
            if(cnt==k) break;
            if(s[i]=='#') continue;
            if(s[i]==c) 
            {
                c = '#';
                ++cnt;
            }
        }
    }
    for(int i=0;i<n;i++) 
    {
        if(s[i]=='#') continue;
        cout<<s[i];
    }
    cout<<endl;
}

void sol2(int tc)
{
    int n,k; cin>>n>>k;
    string s; cin >>s;
    if(k>=n) {cout<<0<<endl; return;}
    while(k)
    {
        bool ok = true;
        for(int i=0;i<s.size()-1;i++)
        {
            if(s[i] < s[i+1])
            {
                ok = false;
                s.erase(s.begin()+i);
                --k;
                //cout<<s<<endl;
                break;
            }
        }
        if(ok) break;
    }

    if(s.size()==0) 
    {
        cout<<0<<endl;
        return;
    }

    for(int i=0;i<s.size()-k;i++) cout<<s[i];
    cout<<endl;
}
int main()
{
    //life_is_a_race
    int t=1; 
    cin>>t;
    for(int i=1;i<=t;i++) sol2(i);
}

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