Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int books_n, libraryes, days;
- int book_weight[2000001];
- vector <pair <long long, long long> > weights;
- vector <vector <int> > library_books;
- long long dp[2000001];
- int ans[2000001];
- vector<int> back_path[200001];
- int viz[10000001];
- void solve(){
- int sum = 0;
- for (int i = weights.size()-1; i > -1; -- i){
- sum += weights[i].first;
- for (int k = min(days, sum); k > -1; -- k){
- if (k != 0 && dp[k] == 0){
- continue;
- }
- int score = 0;
- for (int j = 0; j < library_books[i].size(); ++ j){
- int id = library_books[i][j];
- score += book_weight[id] / viz[id];
- }
- if (dp[k+weights[i].first] < dp[k]+score){
- back_path[k+weights[i].first] = back_path[k];
- back_path[k+weights[i].first].push_back(i);
- dp[k+weights[i].first] = dp[k]+score;
- }
- }
- }
- }
- int main()
- {
- freopen("c_incunabula.txt", "r",stdin);
- cin >> books_n >> libraryes >> days;
- library_books.resize(libraryes);
- for (int k = 0; k < books_n; ++ k){
- cin >> book_weight[k];
- }
- for (int k = 0; k < libraryes; ++ k){
- int book_count, open_time, c;
- cin >> book_count >> open_time >> c;
- long long score = 0;
- for (int i = 0; i < book_count; ++ i){
- int id;
- cin >> id;
- viz[id] ++;
- library_books[k].push_back(id);
- }
- weights.push_back({open_time, score});
- }
- solve();
- freopen("output.txt", "w", stdout);
- int maxx = 0;
- int max_d = -1;
- for (int k = 0 ; k < days; ++ k){
- if (maxx < dp[k]){
- maxx = dp[k];
- max_d = k;
- }
- }
- cout << back_path[max_d].size() << endl;
- for (int k = 0; k < back_path[max_d].size(); ++ k){
- int id = back_path[max_d][k];
- cout << id << ' ' << library_books[id].size() << endl;
- for (int i = 0; i < library_books[id].size(); ++ i){
- cout << library_books[id][i] << ' ';
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement