Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 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. auto val = (double) (1.0 * nbsp / days);
  50. vector<int> inds;
  51. for(int j = 0; j < n; ++ j) {
  52. int x;
  53. cin >> x;
  54. inds.push_back(x);
  55. }
  56. V.push_back(inds);
  57. libs_[i] = {i, val, days, nbsp, inds, 0};
  58. }
  59. sort(libs_.begin(), libs_.end(), cmp_lib);
  60.  
  61. for(int i = 0; i < libs_.size(); ++ i) {
  62. for(auto e : libs_[i].bs)
  63. books[e].libs.push_back(i);
  64. }
  65.  
  66. sort(books.begin(), books.end(), cmp);
  67. int curr_book = 0;
  68. vector<int> marked_lib(l, 0);
  69. vector<int> marked_book(b, 0);
  70. vector<int> out_libs;
  71. int total_sup = 0;
  72. vector< vector <int> > out_books;
  73. while(curr_book < b) {
  74. while(curr_book < b && marked_book[curr_book]) {
  75. curr_book++;
  76. // cout << curr_book;
  77. }
  78. if (curr_book == b) {
  79. break;
  80. }
  81. int indb = books[curr_book].o_ind;
  82. int valb = books[curr_book].score;
  83. int ind_lib = books[curr_book].ind_lib;
  84. vector<int> libs = books[curr_book].libs;
  85. for(int i = ind_lib; i < libs.size(); ++ i) {
  86. if(marked_lib[libs[i]] == 0) {
  87. marked_lib[libs[i]] = 1;
  88. int ind = libs[i];
  89. out_libs.push_back(libs_[ind].o_ind);
  90. out_books.push_back({});
  91. int days = libs_[ind].days;
  92. total_sup += days;
  93. int bpday = libs_[ind].bpday;
  94. vector<int> bs = libs_[ind].bs;
  95. int ind_book = libs_[ind].ind_book;
  96. vector<int> curr_day_books;
  97. int curr_ind_j = 0;
  98.  
  99. vector<int> out_b;
  100. int cur_marked_n = 0;
  101. int bound = (d - total_sup) * bpday;
  102. for(int j = ind_book; j < bs.size(); ++j) {
  103. if(marked_book[bs[j]] == 0) {
  104. out_books.back().push_back(bs[j]);
  105. marked_book[bs[j]] = 1;
  106. cur_marked_n += 1;
  107. }
  108. if(cur_marked_n == bound) {
  109. curr_ind_j = j;
  110. break;
  111. }
  112. }
  113. libs_[ind].ind_book = curr_ind_j;
  114.  
  115. }
  116. }
  117. curr_book += 1;
  118. }
  119. cout << out_libs.size() << endl;
  120. for(int i = 0; i < out_libs.size(); ++ i) {
  121. cout << out_libs[i] << " " << out_books[i].size() << endl;
  122. for(auto e : out_books[i])
  123. cout << e << " ";
  124. cout << endl;
  125. }
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement