-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26-63.cpp
More file actions
51 lines (41 loc) · 1000 Bytes
/
26-63.cpp
File metadata and controls
51 lines (41 loc) · 1000 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
int main() {
fstream F;
F.open("26-63.txt");
int N, S;
F >> N >> S;
int p;
char c;
vector<int> q, z, q1;
for (int i = 0; i < N; ++i) {
F >> p >> c;
if (c == 'Z') z.push_back(p);
if (c == 'Q') q.push_back(p);
}
sort(z.rbegin(), z.rend());
sort(q.rbegin(), q.rend());
int kz = 0;
while (!z.empty() && z.back() <= q.back()) {
if (S < z.back()) break;
++kz;
S -= z.back();
z.pop_back();
}
while (!q.empty()) {
if (S < q.back()) break;
S -= q.back();
q1.push_back(q.back());
q.pop_back();
}
while (!q1.empty() && S + q1.back() >= z.back() && S > 0) {
++kz;
S = S + q1.back() - z.back();
q1.pop_back();
z.pop_back();
}
cout << kz << " " << S;
}