/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 2ms 532.0 KiB

Code

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

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

    vector<pair<int,int>> dq;
    for(int i = 0; i < n; i++){
        dq.push_back({s[i] - '0', i});
    }

    sort(dq.begin(), dq.end());

    for(int i = n - 1; i >= 0; i--){
        auto mx = dq[i];
       // cout << mx.first << ' ' << mx.second << '\n';
        for(auto &x : dq){
            if ( (x.second != n+1) and (x.second < mx.second) and (x.first < mx.first)){
                x.second = n+1;
                k--;
                if ( !k ) break;
            }
        }
        if ( !k ) break;
    }
    //cout << '\n';
    sort( dq.begin(), dq.end(), cmp );
    
    int cnt = n-k;
    for(auto x : dq){
        if ( x.second == n +  1) continue;
        cout << x.first ;
        cnt--;
        if ( cnt == 0 ) break;
    }
    cout << '\n';
}


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 09:19:54
Judged At
2024-11-11 02:35:23
Judged By
Score
0
Total Time
2ms
Peak Memory
532.0 KiB