-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashcode.cpp
More file actions
105 lines (105 loc) · 3 KB
/
hashcode.cpp
File metadata and controls
105 lines (105 loc) · 3 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
98
99
100
101
102
103
104
105
#include <bits/stdc++.h>
using namespace std;
long long tb, tl, td;
class lib
{
public:
long long score, total_books, total_capacity, sign_up_days, lib_id;
set<pair<long long, long long>, greater<pair<long long, long long>>> books_id;
float profit;
void cal_score()
{
long long rem_days = td - sign_up_days;
long long total_scan_books = rem_days * total_capacity;
auto it = books_id.begin();
while (total_scan_books && it != books_id.end())
{
score += (*it).first;
total_scan_books--;
it++;
}
profit = score / td;
}
};
bool compare(const lib &a, const lib &b)
{
return a.profit > b.profit;
}
int main()
{
cin >> tb >> tl >> td;
map<long long, long long> books_score;
long long score;
for (long long i = 0; i < tb; i++)
{
cin >> score;
books_score[i] = score;
}
lib Library[tl];
// long long lib_books, lib_days, lib_capacity;
for (long long i = 0; i < tl; i++)
{
cin >> Library[i].total_books >> Library[i].sign_up_days >> Library[i].total_capacity;
Library[i].lib_id = i;
long long book_id;
for (long long j = 0; j < Library[i].total_books; j++)
{
cin >> book_id;
Library[i].books_id.insert(make_pair(books_score[book_id], book_id));
}
Library[i].cal_score();
}
sort(Library, Library + tl, compare);
map<long long, bool> selected_books;
// long long total_selected_lib = 0;
long long total_days_copy = td;
long long index = 0;
vector<vector<long long>> ans;
vector<long long> Lib_id;
long long ans_ct = 0;
while (total_days_copy && index < tl)
{
// total_selected_lib++;
// cout<<Library[index].lib_id<<" ";
vector<long long> temp_selected_books;
long long rem_days = td - Library[index].sign_up_days;
long long total_scan_books = rem_days * Library[index].total_capacity;
auto it = Library[index].books_id.begin();
// bool flag = false;
while (total_scan_books && it != Library[index].books_id.end())
{
if (!selected_books[(*it).second])
{
temp_selected_books.push_back((*it).second);
selected_books[(*it).second] = true;
// flag = true;
}
it++;
total_scan_books--;
}
if (temp_selected_books.size())
{
ans.push_back(temp_selected_books);
Lib_id.push_back(index);
ans_ct++;
}
total_days_copy -= Library[index].sign_up_days;
index++;
}
cout << ans_ct << endl;
for (long long i = 0; i < ans_ct; i++)
{
// if(ans[i].size()){
cout << Library[Lib_id[i]].lib_id << " " << ans[i].size() << "\n";
for (auto j : ans[i])
{
cout << j << " ";
}
if (i != (ans_ct - 1))
{
cout << "\n";
}
// }
}
return 0;
}