-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKattis_WorkReduction.cpp
More file actions
60 lines (50 loc) · 1.44 KB
/
Kattis_WorkReduction.cpp
File metadata and controls
60 lines (50 loc) · 1.44 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
#include <bits/stdc++.h> // here we have all the STL we need, including istringstream and ostringstream
#define ALL(x) x.begin(), x.end()
#define FAST std::cin.tie(0); ios::sync_with_stdio(false); std::cout.tie(0);
using namespace std;
#define endl "\n";
bool sortbysec(const pair<string,int> &a,
const pair<string,int> &b);
int main() {
int T;
scanf("%d\n", &T);
int n,m,l, a, b, N, cost, lower;
vector<pair<string,int>> vect;
char name[20];
string temp;
string str_name;
for (int i = 1; i <= T; i++) {
vect.clear();
scanf("%d %d %d\n", &n, &m, &l);
while (l--) {
N = n;
getline(cin, str_name, ':');
cin >> a;
cin.ignore();
cin >> b;
cin.ignore();
cost = 0;
while (N >= 2*m) {
if (b < ((N+1)/2)*a) {
N >>= 1;
cost += b;
}
else {
break;
}
}
cost = cost + (N - m)*a;
vect.push_back(make_pair(str_name, cost+0));
}
sort(ALL(vect),sortbysec);
std::printf("Case %d\n", i);
for (auto elem : vect) {
cout << elem.first << " " << elem.second << endl;
}
}
}
bool sortbysec(const pair<string,int> &a,
const pair<string,int> &b)
{
return (a.second < b.second);
}