-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
55 lines (53 loc) · 1.07 KB
/
D.cpp
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
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long check[200005];
int main()
{
fastio;
long long t,n,p,sum,i;
cin>>t;
while(t--)
{
string s;
sum=0;
cin>>s;
cin>>p;
n=s.size();
for(i=0;i<n;i++)
check[i]=0;
vector<pair<long long, long long> > vect;
for(i=0;i<n;i++)
{
long long tmp=s[i]-'a'+1;
sum+=tmp;
vect.push_back(make_pair(tmp,i));
}
if(sum<=p)
{
cout<<s<<"\n";
continue;
}
sort(vect.begin(),vect.end());
if(vect[0].first>p)
{
cout<<"\n";
continue;
}
for(i=n-1;i>=0;i--)
{
check[vect[i].second]=1;
sum-=vect[i].first;
if(sum<=p)
break;
}
for(i=0;i<n;i++)
{
if(check[i]==0)
cout<<s[i];
}
cout<<"\n";
}
return 0;
}