forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1702D-NotACheapString.cpp
More file actions
35 lines (27 loc) · 840 Bytes
/
1702D-NotACheapString.cpp
File metadata and controls
35 lines (27 loc) · 840 Bytes
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
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::ios_base::sync_with_stdio(false);
long t; std::cin >> t;
while(t--){
std::string s; std::cin >> s;
long target; std::cin >> target;
long total(0); std::vector<std::pair<long, long> > w(s.size());
for(long p = 0; p < s.size(); p++){
w[p] = std::make_pair(s[p] - 'a' + 1, p);
total += w[p].first;
}
sort(w.rbegin(), w.rend());
std::vector<bool> v(s.size(), 1);
for(long p = 0; (target < total) && p < s.size(); p++){
total -= w[p].first;
v[w[p].second] = 0;
}
for(long p = 0; p < s.size(); p++){
if(!v[p]){continue;}
std::cout << s[p];
}
std::cout << std::endl;
}
}