/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 3ms 332.0 KiB

Code

/*
 * Author: Md. Mahfuzur Rahman
 * Purpose: Competitive Programming
 */

#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;

#define ll long long
#define pb push_back
#define endl '\n'
#define nl cout << endl
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define srt(v) sort(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<long,long>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define minheap priority_queue<long long, vector<long long>, greater<long long>>
#define maxheap priority_queue<long long, vector<long long>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const int MAX = 1e6;

#define debug(x) cout<<#x<<" = ";deb(x);
template <typename T>
void deb(T x) { cout <<"[ "<< x << " ]\n"; }
template <typename T, typename U>
void deb(pair<T, U> p) { cout << "(" << p.first << ", " << p.second << ")\n"; }
template <typename T>
void deb(vector<T> v){cout<<"[ ";for (T val : v) cout << val << " ";cout<<"]"<<endl;}
template <typename T>
void deb(vector<vector<T>> v){for (auto row : v)deb(row);}
template <typename T, typename U>
void deb(vector<pair<T, U>> vec){for ( auto p : vec){deb(p);}cout << endl;}
template <typename T, typename U>
void deb(map<T,U>mp){for(auto x:mp)cout<<"\n( "<<x.first<<" "<<x.second<<" )";cout<<endl;}
template<typename T>
void deb(set<T>set){cout<<"[ ";for(auto x:set)cout<<x<<" ";cout<<"]\n";}
template <typename... T>
void read(T&... args){((cin>>args), ...);}
template <typename... T>
void write(T... args){((cout<<args<<" "), ...);}

bitset<MAX> is_prime;
vector<int> primes;
void sieve()
{
    is_prime.set();
    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i)
    {
        if (is_prime[i])
        {
            primes.pb(i);
            for (int j = i * i; j < MAX; j += i)
            {
                is_prime[j] = 0;
            }
        }
    }
}

ll mod_add(ll a, ll b, ll m = MOD) { return (a % m + b % m) % m; }
ll mod_sub(ll a, ll b, ll m = MOD) { return ((a % m - b % m) + m) % m; }
ll mod_mul(ll a, ll b, ll m = MOD) { return (a % m * b % m) % m; }
ll mod_pow(ll a, ll b, ll m = MOD)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = mod_mul(res, a, m);
        
        a = mod_mul(a, a, m);
        b >>= 1;
    }
    return res;
}

// File I/O (uncomment if needed)
// ifstream infile("input.txt");
// ofstream outfile("output.txt");
  int tcc=1;
  int t = 1;
void solve(int tc)
{
    ll n,d;cin>>n>>d;
    ll a,b; cin>>a>>b;
    if(d<=n)
    cout<<d*a+(n-d)*b<<endl;
else{
    cout<<n*a<<endl;
}
   
}
void solve2(ll tc)
{
    int n,k; cin>>n>>k;
    string s; cin>>s;
    vector<pair<char,int>>v;
    if(s.size()==0)
    {
        cout<<0<<endl;return;
    }
    for(int i=0; i<n; i++)
    {
        v.push_back({s[i],i});
    }
    sort(v.begin(), v.end());
    reverse(all(v));

    vector<int>v2;
    for(int i=0; i<n; i++)
    {
        v2.push_back(v[i].second);
    }
    if(n==k){
        cout<<0<<endl;
        return;}
    if(k==0 || n==0){
        cout<<s<<endl;
        return;
    }
    string ans="";
    int x = n-k;
    int pind = -1;
    while(x)
    {
    
        for(int i=0; i<v2.size(); i++)
        {
            if(n-v2[i]>=x && v2[i]>pind){
                ans+=s[v2[i]];
                pind = v2[i];
                break;
            }
        }
        x--;
    }
    cout<<ans;
    cout<<endl;

    

}

int main()
{
    FAST_IO;
    
  
    cin >> tcc;
    t=tcc;
    ll a=1;
    while (tcc--)
    {
        solve2(a++);
    }
    // For file I/O
    // infile.close();
    // outfile.close();
    return 0;
}

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 11:33:18
Judged At
2024-11-11 02:34:53
Judged By
Score
0
Total Time
3ms
Peak Memory
332.0 KiB