USACO Greedy Gift Givers

Code

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
/*
ID: wcr19961
PROG: gift1
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
const int maxn = 15;
char s[maxn][maxn];
int sum[maxn];
map<string, int> dict;
int main() {
freopen("gift1.in", "r", stdin);
freopen("gift1.out", "w", stdout);
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%s", s[i]);
dict[s[i]] = i;
}
for (int i = 0; i < n; ++i) {
int x, y;
char s1[maxn], s2[maxn];
scanf("%s%d%d", s1, &x, &y);
for (int j = 0; j < y; ++j) {
scanf("%s", s2);
sum[dict[s2]] += x / y;
sum[dict[s1]] -= x / y;
}
}
for (int i = 0; i < n; ++i) {
printf("%s %d\n", s[i], sum[i]);
}
return 0;
}