/ SeriousOJ /

Record Detail

Wrong Answer


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

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll>vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef list<int> li;
typedef set<int> sti;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;
typedef unordered_set<ll> us;
typedef priority_queue<ll> pq;
typedef deque<ll> dq;
#define nl "\n"
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define Yes cout<<"YES\n";
#define No cout<<"NO\n";
#define yes cout<<"Yes\n";
#define no cout<<"No\n";
#define F first
#define sc second
#define all(v) v.begin(), v.end()
#define sortv(v) sort(v.begin(), v.end());
#define rsort(v) sort(v.rbegin(), v.rend());
#define revv(v) reverse(v.begin(), v.end());

const int N=1e6+9;
const int mod1=1e9+7, mod2=1e9+9;
const int base1=29, base2=67;
const long long int inf=1e18;
#define saiful_islam_bk

void solve(){
    ll n, m; cin>>n>>m; string s; cin>>s;
    map<char, vector<ll>>mp;
    for(ll i=0;i<n;i++)
    {
        mp[s[i]].pb(i);         
    }
    for(ll i=0;i<n;i++)
    {
        if(m==0) break;
        for(char j='a';j<s[i];j++)
        {
                if(mp[j].size()){
                    swap(s[i], s[mp[j].back()]);
                    mp[j].pop_back();
                    m--;
                }
        }           
    }
    cout<<s<<nl;
}
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
    saiful_islam_bk
    ll test=1;
     cin>>test;
    for(ll ii=1; ii<=test; ii++){
        //cout<<"Case "<<ii<<": ";
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1058 Lexicographically Smallest String
Contest
Sylhet ICPC 2024 Collaborative Challenge: Episode 2
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-30 09:30:45
Judged At
2024-11-11 02:35:20
Judged By
Score
5
Total Time
2ms
Peak Memory
532.0 KiB