Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5. struct book {
  6. int o_ind;
  7. int score;
  8. vector<int> libs;
  9. int ind_lib;
  10. };
  11.  
  12. struct library{
  13. int o_ind;
  14. double val;
  15. int days;
  16. int bpday;
  17. vector<int> bs;
  18. int ind_book;
  19. };
  20.  
  21. bool cmp(book a, book b) {
  22. if(a.score == b.score) return a.o_ind < b.o_ind;
  23. return a.score > b.score;
  24. }
  25. bool cmp_lib(library l1, library l2) {
  26. if(l1.val == l2.val) return l1.bs.size() < l2.bs.size();
  27. return l1.val > l2.val;
  28. }
  29. int main() {
  30.  
  31. freopen("input.txt", "r", stdin);
  32. freopen("output2.txt", "w", stdout);
  33.  
  34. int b, l ,d;
  35. cin >> b >> l >> d;
  36. vector<book> books(b);
  37. vector<library> libs_(l);
  38. for(int i = 0; i < b; ++ i) {
  39. int x;
  40. cin >> x;
  41. vector<int> v = {};
  42. books[i] = {i, x, v, 0};
  43. }
  44. vector< vector<int> > V(l);
  45.  
  46. for(int i = 0; i < l; ++ i) {
  47. int n, days, nbsp;
  48. cin >> n >> days >> nbsp;
  49. int total_score = 0;
  50. vector<int> inds;
  51. for(int j = 0; j < n; ++ j) {
  52. int x;
  53. cin >> x;
  54. inds.push_back(x);
  55. total_score += books[x].score;
  56. }
  57. auto val = (double) (1.0 * total_score * nbsp / days);
  58. V.push_back(inds);
  59. libs_[i] = {i, val, days, nbsp, inds, 0};
  60. }
  61. sort(libs_.begin(), libs_.end(), cmp_lib);
  62.  
  63. for(int i = 0; i < libs_.size(); ++ i) {
  64. for(auto e : libs_[i].bs)
  65. books[e].libs.push_back(i);
  66. }
  67.  
  68. sort(books.begin(), books.end(), cmp);
  69. int curr_book = 0;
  70. vector<int> marked_lib(l, 0);
  71. vector<int> marked_book(b, 0);
  72. vector<int> out_libs;
  73. int total_sup = 0;
  74. vector< vector <int> > out_books;
  75. while(curr_book < b) {
  76. while(curr_book < b && marked_book[curr_book]) {
  77. curr_book++;
  78. // cout << curr_book;
  79. }
  80. if (curr_book == b) {
  81. break;
  82. }
  83. int indb = books[curr_book].o_ind;
  84. int valb = books[curr_book].score;
  85. int ind_lib = books[curr_book].ind_lib;
  86. vector<int> libs = books[curr_book].libs;
  87. for(int i = ind_lib; i < libs.size(); ++ i) {
  88. if(marked_lib[libs[i]] == 0) {
  89. marked_lib[libs[i]] = 1;
  90. int ind = libs[i];
  91. out_libs.push_back(libs_[ind].o_ind);
  92. out_books.push_back({});
  93. int days = libs_[ind].days;
  94. total_sup += days;
  95. int bpday = libs_[ind].bpday;
  96. vector<int> bs = libs_[ind].bs;
  97. int ind_book = libs_[ind].ind_book;
  98. vector<int> curr_day_books;
  99. int curr_ind_j = 0;
  100.  
  101. vector<int> out_b;
  102. int cur_marked_n = 0;
  103. int bound = (d - total_sup) * bpday;
  104. for(int j = ind_book; j < bs.size(); ++j) {
  105. if(marked_book[bs[j]] == 0) {
  106. out_books.back().push_back(bs[j]);
  107. marked_book[bs[j]] = 1;
  108. cur_marked_n += 1;
  109. }
  110. if(cur_marked_n == bound) {
  111. curr_ind_j = j;
  112. break;
  113. }
  114. }
  115. libs_[ind].ind_book = curr_ind_j;
  116. }
  117. }
  118. curr_book += 1;
  119. }
  120. int output_n = 0;
  121. for (int i = 0; i < out_libs.size(); ++ i) {
  122. if (out_books[i].size() > 0) {
  123. output_n += 1;
  124. }
  125. }
  126. cout << output_n << "\n";
  127. for(int i = 0; i < out_libs.size(); ++ i) {
  128. if (out_books[i].size() == 0) {
  129. continue;
  130. }
  131. cout << out_libs[i] << " " << out_books[i].size() << endl;
  132. for(auto e : out_books[i])
  133. cout << e << " ";
  134. cout << endl;
  135. }
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement