-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyTreat.cpp
78 lines (62 loc) · 1.31 KB
/
MyTreat.cpp
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
72
73
74
75
76
77
78
// Problem link: https://csacademy.com/ieeextreme-practice/task/my-treat
// By: Osama Khallouf
#include <bits/stdc++.h>
using namespace std;
map <string, int> counter;
int main() {
int t;
cin >> t;
while(t--){
counter.clear();
int m; cin >> m;
for(int i = 0; i < m; i++) {
string name;
cin >> name;
int ppl ;
cin >> ppl;
counter[name] += ppl;
for(int j = 0; j < ppl; j++) {
string name2;
cin >> name2;
counter[name2]--;
}
}
int meals = 0, days = 0;
for(auto element : counter) {
int x = element.second;
if (x <= 0) continue;
meals += x;
days = max(days, x);
}
cout << meals << ' ' << days << endl;
}
return 0;
}
/*
Alice 1 Bob
Chuck 1 Dave
Dave 1 Eve
Alice -> need 1 meal
Chuck -> need 1 meal
Bob -> needs to pay for 1 meal
Eve -> needs to pay for 1 meal
Day 1:
Bob 1 Alice
Eve 1 Chuck
[2, 1]
-------------------------------------
Alice 2 Bob Chuck
Chuck 1 Bob
Dave 2 Alice Bob
Alice 1 Eve
Alice -> needs 2 meals
Dave -> needs 2 meals
Bob -> needs to pay for 3 meals
Eve -> needs to pay for 1 meal
Day 1:
Bob 2 Alice Dave
Day 2:
Bob 1 Alice
Eve 1 Dave
[4, 2]
*/