-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
97 lines (86 loc) · 2.23 KB
/
Copy pathmain.cpp
File metadata and controls
97 lines (86 loc) · 2.23 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#define MAXSIZE 70
#define MAXN 9999
#define MAXND MAXN / 10
#define INF 99999999
#define MAXEDGE 1000000
#define MAXVERTEX 10
#define EPS 0.00001
#define PI 3.14159265
#define nil NULL
typedef long long ll;
using namespace std;
int n;
int list[MAXSIZE][MAXSIZE], dayPeople[MAXSIZE];
map<int, string> mp;
vector<string> ans[MAXSIZE];
int solve() {
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > student;
set<pair<int, int> > day;
int vis[MAXSIZE], maxDay = -1;
for (int i = 0; i < n; i++) {
student.push(make_pair(0, i));
}
for (int i = 1; i <= n; i++) {
day.insert(make_pair(dayPeople[i], i));
vis[i] = 0;
}
int counter = 0;
while (counter < n * 2) {
pair<int, int> cur = student.top();
int curStu = cur.second;
student.pop();
for (set<pair<int, int> >::iterator it = day.begin(); it != day.end(); it++) {
pair<int, int> d = *it;
if (list[curStu][d.second]) {
list[curStu][d.second] = 0;
vis[d.second]++;
cur.first++;
ans[d.second].push_back(mp[curStu]);
maxDay = max(cur.first, maxDay);
student.push(cur);
day.erase(it);
if (vis[d.second] < 2) {
d.first--;
day.insert(d);
}
counter++;
break;
}
}
}
return maxDay;
}
int main() {
int m, d, day;
string name;
ios::sync_with_stdio(false);
cin >> m >> n;
for (int i = 0; i < m; i++) {
cin >> name >> d;
mp[i] = name;
while (d--) {
cin >> day;
list[i][day] = 1;
dayPeople[day]++;
}
}
int maxDay = solve();
cout << maxDay << endl;
for (int i = 1; i <= n; i++) {
cout << "Day " << i << " ";
cout << ans[i][0] << " " << ans[i][1] << endl;
}
return 0;
}