-
Notifications
You must be signed in to change notification settings - Fork 0
/
UsbAndPS.cpp
99 lines (86 loc) · 2.2 KB
/
UsbAndPS.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
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
/* https://codeforces.com/problemset/problem/762/B
#greedy #two-pointer #sorting
*/
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool helper(int& t1, int& t2) {
if (t1 > 0) {
t1--;
return true;
} else if (t2 > 0) {
t2--;
return true;
}
return false;
}
int main() {
int a, b, c;
cin >> a >> b >> c;
int m;
cin >> m;
vector<int> usbMouseVector(m);
vector<int> psMouseVector(m);
int countUSB=0, countPS = 0;
int cost;
string name;
for(int i=0; i < m; i++) {
cin >> cost >> name;
if (name == "USB") {
usbMouseVector[countUSB] = cost;
countUSB++;
} else {
psMouseVector[countPS] = cost;
countPS++;
}
}
usbMouseVector.resize(countUSB);
psMouseVector.resize(countPS);
sort(usbMouseVector.begin(), usbMouseVector.end());
sort(psMouseVector.begin(), psMouseVector.end());
int sumComputer = 0;
long long sumCost = 0;
int idxUSB = 0;
int idxPS = 0;
while (idxPS < psMouseVector.size() && idxUSB < usbMouseVector.size()) {
if ( a == 0 && b == 0 && c == 0 ) break;
if ((psMouseVector[idxPS]) < usbMouseVector[idxUSB]) {
if (helper(b, c)) {
sumComputer += 1;
sumCost += psMouseVector[idxPS];
++idxPS;
} else {
break;
}
} else {
if (helper(a, c)){
sumComputer += 1;
sumCost += usbMouseVector[idxUSB];
++idxUSB;
} else {
break;
}
}
}
while (idxUSB < usbMouseVector.size()) {
if (helper(a, c)){
sumComputer += 1;
sumCost += usbMouseVector[idxUSB];
++idxUSB;
} else {
break;
}
}
while (idxPS != psMouseVector.size() ) {
if (helper(b, c)) {
sumComputer += 1;
sumCost += psMouseVector[idxPS];
++idxPS;
} else {
break;
}
}
cout << sumComputer << " " << sumCost << endl;
return 0;
}