-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrong.cpp
More file actions
119 lines (98 loc) · 3.79 KB
/
wrong.cpp
File metadata and controls
119 lines (98 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include<bits/stdc++.h>
#define int long long
#define uint unsigned long long
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define fr(i,n) for(int i=0; i<(n); i++)
#define rep(i,a,n) for(int i=(a); i<=(n); i++)
#define nl cout<<"\n"
#define dbg(var) cout<<#var<<"="<<var<<" "
#define all(v) v.begin(),v.end()
#define srt(v) sort(v.begin(),v.end()) // sort
#define mxe(v) *max_element(v.begin(),v.end()) // find max element in vector
#define mne(v) *min_element(v.begin(),v.end()) // find min element in vector
#define unq(v) v.resize(distance(v.begin(), unique(v.begin(), v.end())));
// make sure to sort before applying unique // else only consecutive duplicates would be removed
#define bin(x,y) bitset<y>(x)
using namespace std;
int MOD=1e9+7; // Hardcoded, directly change from here for functions!
void modadd(int &a , int b) {a=((a%MOD)+(b%MOD))%MOD;}
void modsub(int &a , int b) {a=((a%MOD)-(b%MOD)+MOD)%MOD;}
void modmul(int &a , int b) {a=((a%MOD)*(b%MOD))%MOD;}
// ================================== take ip/op like vector,pairs directly!==================================
template<typename typC,typename typD> istream &operator>>(istream &cin,pair<typC,typD> &a) { return cin>>a.first>>a.second; }
template<typename typC> istream &operator>>(istream &cin,vector<typC> &a) { for (auto &x:a) cin>>x; return cin; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const pair<typC,typD> &a) { return cout<<a.first<<' '<<a.second; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) { for (auto &x:a) cout<<x<<'\n'; return cout; }
template<typename typC> ostream &operator<<(ostream &cout,const vector<typC> &a) { int n=a.size(); if (!n) return cout; cout<<a[0]; for (int i=1; i<n; i++) cout<<' '<<a[i]; return cout; }
// ===================================END Of the input module ==========================================
void solve(){
int n=1,p=0,q=0;
string s;
cin>>n>>p>>q>>s;
string res=s;
int orgp=0,orgq=q;
multiset<int, greater<int> > ps,qs;
for(int i=0;i<n;i++){
int l=s[i]-'a';
int r='z'-s[i]+1;
if(s[i]=='a') continue;
// q would always be worth! p won't be if p<r...
if(p>=r){
p-=r;
res[i]='a';
ps.insert(r);
}
else if(q>=l){
q-=l;
res[i]='a';
qs.insert(l);
}
else{ // using p isn't advisable it's best to use q only!
while(q<100*l && qs.size() && p>=(26-*qs.begin())){
p-=(26-*qs.begin());
q+=*qs.begin();
ps.insert(*qs.begin());
qs.erase(qs.begin());
}
while(p<r && ps.size() && q>=(26-*ps.begin())){
q-=(26-*ps.begin());
p+=*ps.begin();
qs.insert(*ps.begin());
ps.erase(ps.begin());
}
if(p>=r){
res[i]='a';
ps.insert(r);
p-=r;
}
else{
while(q<l && qs.size() && p>=(26-*qs.begin())){
p-=(26-*qs.begin());
q+=*qs.begin();
ps.insert(*qs.begin());
qs.erase(qs.begin());
}
res[i]=s[i]-min(l,q);
qs.insert(min(l,q));
q-=min(l,q);
}
}
}
// cout<<p<<" "<<q<<"\n";
cout<<res<<"\n";
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}