-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva00119.cpp
More file actions
71 lines (57 loc) · 1.51 KB
/
uva00119.cpp
File metadata and controls
71 lines (57 loc) · 1.51 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
/* Rishikesh
* UVA 00119 Greed Gift Givers
* I used udebug to solve this problem. This is a problem from the 90s
* and it
* has all the kinks which have since been ironed out. Moreover
* STL and java libraries have made this much easier that it would have been
* at the time.
*/
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<map>
#include<numeric>
#include<algorithm>
using namespace std;
int main() {
#ifdef DEBUGUVA
freopen("test", "r", stdin);
cerr << "This is DEBUG\n";
#endif
int N;
cin >> N;
while(true) {
map<string, int> bal;
vector<string> names(N);
for(int i = 0; i < N; i++) {
cin >> names[i];
bal[names[i]] = 0;
}
for (int i = 0; i < N; i++) {
string name;
int money, n;
cin >> name;
cin >> money >> n;
if (n == 0) {
//bal[name] += money;
continue;
}
int portion = money/n;
bal[name] = bal[name] - money + money % n; // We keep the what is not
// distributed
for (int j = 0; j < n; j++) {
cin >> name;
bal[name] += portion;
}
}
for(int i = 0; i < N; i++) {
cout << names[i] << " " << bal[names[i]] << endl;
}
cin >> N;
if (cin.eof())
break;
else
cout << "\n";
}
}