-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path10670.cpp
More file actions
53 lines (43 loc) · 1.05 KB
/
10670.cpp
File metadata and controls
53 lines (43 loc) · 1.05 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
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int reduce(int a, int b, int m, int w) {
int price = 0;
while (w > m) {
if (w/2 >= m and (w/2)*a >= b) w /= 2, price += b;
else w -= 1, price += a;
}
return price;
}
typedef pair<string, int> si;
struct comp {
bool operator()(const si &lhs, const si &rhs) {
if (lhs.second == rhs.second) return lhs.first < rhs.first;
return lhs.second < rhs.second;
}
};
int main() {
int tc, n, m, l;
string null;
cin >> tc;
for (int t = 1; t <= tc; t++) {
cin >> n >> m >> l;
getline(cin, null);
vector<si> ans;
for (int i = 0; i < l; i++) {
int a, b; string name, in;
getline(cin, name, ':');
getline(cin, in, ','); a = stoi(in);
getline(cin, in); b = stoi(in);
ans.push_back(make_pair(name, reduce(a, b, m, n)));
}
sort(ans.begin(), ans.end(), comp());
cout << "Case " << t << endl;
for (auto &it : ans) {
cout << it.first << ' ' << it.second << endl;
}
}
return 0;
}