/ 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
#define bug(a) cout<< #a << " : " << a <<endl;
#define bug2(a, b) cout<< #a << " : " << a  << " " << #b << " : " << b << endl;

void solve(int cs){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if(k == n){
        cout << 0 << '\n';
        return;
    }
    vector<int> idx[10];
    for(int i = 0;i < n;i++){
        idx[s[i] - '0'].push_back(i);
    }
    for(int i = 0;i <= 9;i++){
        sort(idx[i].rbegin(), idx[i].rend());
    }
    vector<bool> ok(n, true);
    while(k--){
        for(int i = 0;i < 10;i++){
            if(idx[i].size()){
                ok[idx[i].back()] = false;
                idx[i].pop_back();
                break;
            }
        }
    }
    for(int i = 0;i < n;i++){
        if(ok[i]) cout << s[i];
    }
    cout << '\n';
    
}


int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.tie(0);

    int tc = 1;
    cin >> tc;

    for(int cs = 1; cs <= tc; cs++){
        solve(cs);
    }
}

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:38:41
Judged At
2024-11-11 02:35:05
Judged By
Score
0
Total Time
2ms
Peak Memory
532.0 KiB