-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path102C_Homework.cpp
More file actions
129 lines (107 loc) · 3.1 KB
/
102C_Homework.cpp
File metadata and controls
129 lines (107 loc) · 3.1 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
120
121
122
123
124
125
126
127
128
129
// 364213192 Feb/24/2026 22:55UTC+7 Minh4893IT C - Homework C++17 (GCC 7-32) Accepted 92 ms 100 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define IF(cond, t, f) (cond ? t : f)
#define OFILE(finp, fout) freopen(finp, "r", stdin), freopen(fout, "w", stdout)
#define FAST_IO ios_base::sync_with_stdio(false), (void)cin.tie()
#define MULTI \
int t; \
cin >> t; \
while (t--)
template <class T, class V>
ostream &operator<<(ostream &o, pair<T, V> p);
#define P(T, O, C) \
template <class U> \
ostream &operator<<(ostream &o, T<U> v) \
{ \
o << O; \
int f = 0; \
for (auto &i : v) \
o << (f++ ? ", " : "") << i; \
return o << C; \
}
#define Q(T, O, C) \
template <class K, class V> \
ostream &operator<<(ostream &o, T<K, V> v) \
{ \
o << O; \
int f = 0; \
for (auto &i : v) \
o << (f++ ? ", " : "") << i; \
return o << C; \
}
P(vector, '[', ']')
P(set, '{', '}')
Q(map, '{', '}')
template <class T, class V>
ostream &operator<<(ostream &o, pair<T, V> p)
{
return o << "(" << p.first << ", " << p.second << ")";
}
template <class T, size_t N>
ostream &operator<<(ostream &o, array<T, N> v)
{
o << "[";
int f = 0;
for (auto &i : v)
o << (f++ ? ", " : "") << i;
return o << "]";
}
void dbg(const char *s) { cerr << endl; }
template <class T, class... A>
void dbg(const char *s, T v, A... a)
{
const char *c = s;
int b = 0;
while (*c && (*c != ',' || b))
b += bool(strchr("({[", *c)), b -= bool(strchr(")}]", *c)), c++;
cerr.write(s, c - s) << " = " << v << (sizeof...(a) ? " |" : "");
if (sizeof...(a))
dbg(c + 1, a...);
else
cerr << endl;
}
#ifdef LOCAL
#define debug(...) dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
void solve()
{
string s;
cin >> s;
int k;
cin >> k;
map<char, int> freq;
for (char c : s)
freq[c]++;
vector<pair<char, int>> chars(freq.begin(), freq.end());
sort(chars.begin(), chars.end(), [](const pair<char, int> &a, const pair<char, int> &b)
{ return a.second < b.second; });
set<char> omit;
for (auto &[c, f] : chars)
{
if (f <= k)
{
omit.insert(c);
k -= f;
}
else
break;
}
string result;
for (char c : s)
if (omit.count(c) == 0)
result += c;
cout << freq.size() - omit.size() << endl;
cout << result << endl;
}
signed main()
{
FAST_IO;
// MULTI
solve();
return 0;
}