Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 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 viz[10000001];
  15. void solve(){
  16.  
  17. int sum = 0;
  18. for (int i = weights.size()-1; i > -1; -- i){
  19. sum += weights[i].first;
  20. for (int k = min(days, sum); k > -1; -- k){
  21.  
  22. if (k != 0 && dp[k] == 0){
  23. continue;
  24. }
  25.  
  26. int score = 0;
  27. for (int j = 0; j < library_books[i].size(); ++ j){
  28. int id = library_books[i][j];
  29. score += book_weight[id] / viz[id];
  30. }
  31.  
  32. if (dp[k+weights[i].first] < dp[k]+score){
  33. back_path[k+weights[i].first] = back_path[k];
  34. back_path[k+weights[i].first].push_back(i);
  35.  
  36. dp[k+weights[i].first] = dp[k]+score;
  37. }
  38.  
  39.  
  40. }
  41. }
  42.  
  43. }
  44. int main()
  45. {
  46.  
  47. freopen("c_incunabula.txt", "r",stdin);
  48.  
  49. cin >> books_n >> libraryes >> days;
  50.  
  51. library_books.resize(libraryes);
  52.  
  53. for (int k = 0; k < books_n; ++ k){
  54. cin >> book_weight[k];
  55. }
  56.  
  57.  
  58. for (int k = 0; k < libraryes; ++ k){
  59. int book_count, open_time, c;
  60. cin >> book_count >> open_time >> c;
  61. long long score = 0;
  62. for (int i = 0; i < book_count; ++ i){
  63. int id;
  64. cin >> id;
  65. viz[id] ++;
  66. library_books[k].push_back(id);
  67. }
  68.  
  69. weights.push_back({open_time, score});
  70. }
  71.  
  72.  
  73. solve();
  74. freopen("output.txt", "w", stdout);
  75.  
  76. int maxx = 0;
  77. int max_d = -1;
  78.  
  79. for (int k = 0 ; k < days; ++ k){
  80. if (maxx < dp[k]){
  81. maxx = dp[k];
  82. max_d = k;
  83. }
  84. }
  85.  
  86.  
  87. cout << back_path[max_d].size() << endl;
  88. for (int k = 0; k < back_path[max_d].size(); ++ k){
  89. int id = back_path[max_d][k];
  90. cout << id << ' ' << library_books[id].size() << endl;
  91.  
  92. for (int i = 0; i < library_books[id].size(); ++ i){
  93. cout << library_books[id][i] << ' ';
  94. }
  95. cout << endl;
  96. }
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement