-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path119 - Greedy Gift Givers
70 lines (67 loc) · 1.26 KB
/
119 - Greedy Gift Givers
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
//Author: Fuadul Hasan([email protected])
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding cin.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long
#define pr pair<int, int>
#define vpr vector<pr>
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
#define Test printf("Case %d: ",tc++);
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
const int mod = 1e9 + 7;
const ll Inf = (ll)2e18 + 5;
const int N = 2e5 + 5;
int solve()
{
//happy coding
/*size_t t = 1;
size_t n;*/
int t = 1;
int n;
//cin>>n;
std::map<string, int> m;
while(cin>>n){
m.clear();
string zz[n+1];
string s,z;
for(int i=0;i<n;i++){
//string s;
cin>>s;
zz[i] = s;
//m[s] = 0;
}
//string s,z;
int p,d;
for(int i=0;i<n;i++){
cin>>s>>d>>p;
if(p==0) continue;
m[s] = (m[s] - d);
m[s]+=(d%p);
int g = d/p;
for(int j=0;j<p;j++){
//string z;
cin>>z;
m[z] += g;
}
}
if(t++>1) cout<<endl;
for(int i=0;i<n;i++){
cout<<zz[i]<<" "<<m[zz[i]]<<endl;
}
}
return 0;
}
int main(){
int test = 1;
//scanf("%d", &test);
while (test--)solve();return 0;
}