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 x[10002][10002];
- void solve(){
- for (int i = 0; i < weights.size(); ++ i){
- cout << i << endl;
- for (int k = days; k > -1; -- k){
- if (k != 0 && dp[k] == 0){
- continue;
- }
- long long score = weights[i].second;
- for (int i = 0; i < back_path[k].size(); ++ i){
- int id = back_path[k][i];
- score -= x[id][i] / 4;
- }
- 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;
- }
- }
- }
- }
- vector<int> books_in_library[100001];
- 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;
- for (int j = 0; j < books_in_library[id].size(); ++ j){
- x[books_in_library[id][j]][k] += book_weight[id];
- x[k][books_in_library[id][j]] += book_weight[id];
- }
- books_in_library[id].push_back(k);
- library_books[k].push_back(id);
- score += book_weight[id];
- }
- weights.push_back({open_time, score});
- }
- solve();
- int maxx = 0;
- int max_d = -1;
- for (int k = 0 ; k < days; ++ k){
- if (maxx < dp[k]){
- maxx = dp[k];
- max_d = k;
- }
- }
- freopen("output.txt", "w", stdout);
- 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