Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int books_n, libraryes, days;
  6. int book_weight[2000001];
  7. vector <pair <long long, long long> > weights;
  8.  
  9. vector <vector <int> > library_books;
  10.  
  11. long long dp[2000001];
  12. int ans[2000001];
  13. vector<int> back_path[200001];
  14. int x[10002][10002];
  15.  
  16. void solve(){
  17.  
  18.  
  19. for (int i = 0; i < weights.size(); ++ i){
  20. cout << i << endl;
  21. for (int k = days; k > -1; -- k){
  22.  
  23. if (k != 0 && dp[k] == 0){
  24. continue;
  25. }
  26.  
  27.  
  28. long long score = weights[i].second;
  29. for (int i = 0; i < back_path[k].size(); ++ i){
  30. int id = back_path[k][i];
  31. score -= x[id][i] / 4;
  32. }
  33.  
  34. if (dp[k+weights[i].first] < dp[k] + score){
  35. back_path[k+weights[i].first] = back_path[k];
  36. back_path[k+weights[i].first].push_back(i);
  37.  
  38. dp[k+weights[i].first] = dp[k]+score;
  39. }
  40.  
  41.  
  42. }
  43. }
  44.  
  45. }
  46.  
  47.  
  48. vector<int> books_in_library[100001];
  49. int main()
  50. {
  51.  
  52. freopen("c_incunabula.txt", "r",stdin);
  53.  
  54. cin >> books_n >> libraryes >> days;
  55.  
  56. library_books.resize(libraryes);
  57.  
  58. for (int k = 0; k < books_n; ++ k){
  59. cin >> book_weight[k];
  60. }
  61.  
  62.  
  63. for (int k = 0; k < libraryes; ++ k){
  64. int book_count, open_time, c;
  65. cin >> book_count >> open_time >> c;
  66. long long score = 0;
  67. for (int i = 0; i < book_count; ++ i){
  68. int id;
  69. cin >> id;
  70.  
  71. for (int j = 0; j < books_in_library[id].size(); ++ j){
  72. x[books_in_library[id][j]][k] += book_weight[id];
  73. x[k][books_in_library[id][j]] += book_weight[id];
  74. }
  75. books_in_library[id].push_back(k);
  76.  
  77.  
  78. library_books[k].push_back(id);
  79. score += book_weight[id];
  80.  
  81. }
  82.  
  83. weights.push_back({open_time, score});
  84. }
  85.  
  86.  
  87.  
  88. solve();
  89.  
  90. int maxx = 0;
  91. int max_d = -1;
  92.  
  93. for (int k = 0 ; k < days; ++ k){
  94. if (maxx < dp[k]){
  95. maxx = dp[k];
  96. max_d = k;
  97. }
  98. }
  99.  
  100.  
  101. freopen("output.txt", "w", stdout);
  102.  
  103. cout << back_path[max_d].size() << endl;
  104. for (int k = 0; k < back_path[max_d].size(); ++ k){
  105. int id = back_path[max_d][k];
  106. cout << id << ' ' << library_books[id].size() << endl;
  107.  
  108. for (int i = 0; i < library_books[id].size(); ++ i){
  109. cout << library_books[id][i] << ' ';
  110. }
  111. cout << endl;
  112. }
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement