Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. vector< pair< vector<ll>, vector< pair<ll,ll> > > > libraries;
  5. ll b, l, d, x; // books, libraries, days
  6. ll bt[101000] = {};
  7. ll lt[101000] = {};
  8. bool cmp(pair< vector<ll>, vector< pair<ll,ll> > > left, pair< vector<ll>, vector< pair<ll,ll> > > right ){
  9. ll s1 = left.first[3];
  10. ll s2 = right.first[3];
  11. double t1 = left.first[1]*left.first[1];
  12. double t2 = right.first[1]*right.first[1];
  13. double idx1, idx2;
  14. idx1 = s1/t1;
  15. idx2 = s2/t2;
  16. return idx1 > idx2;
  17. }
  18.  
  19. void scoring(){
  20. ll score = 0;
  21. for(int i=0;i<l;i++){
  22. score = 0;
  23. sort(libraries[i].second.begin(),libraries[i].second.end(), greater<pair<ll, ll>>());
  24. ll books_total = (d - libraries[i].first[1]) * libraries[i].first[2];
  25. for(int j=0;j<books_total and j < libraries[i].first[0] ;j++){
  26. if(bt[libraries[i].second[j].second]){
  27. books_total+=1;
  28. continue;
  29. }
  30. score+= libraries[i].second[j].first;
  31. bt[libraries[i].second[j].second];
  32. //cout << libraries[i].second[j].first << " ";
  33. }
  34. //cout << '\n';
  35. //cout << i << " " << score << '\n';
  36. libraries[i].first[3] = score;
  37. }
  38. }
  39.  
  40. int main(){
  41. freopen("e_so_many_books.txt", "r", stdin);
  42. freopen("e_out_3.txt", "w", stdout);
  43. cin >> b >> l >> d;
  44. ll book_scores[b+5];
  45. for(int i=0;i<b;i++){
  46. cin >> book_scores[i];
  47. }
  48. for(int i=0;i<l;i++){
  49. pair< vector<ll>, vector< pair<ll,ll> > > dummy;
  50. cin >> x;
  51. dummy.first.emplace_back(x); // number of books
  52. cin >> x;
  53. dummy.first.emplace_back(x);// time of days for signup
  54. cin >> x;
  55. dummy.first.emplace_back(x); // number of books to be shipped per day
  56. dummy.first.emplace_back(0); // initial score index 3
  57. dummy.first.emplace_back(i); // library number
  58. for(int j=0; j<dummy.first[0];j++){
  59. cin >> x;
  60. dummy.second.emplace_back(book_scores[x],x);
  61. }
  62. libraries.emplace_back(dummy);
  63. }
  64. cout << l << '\n';
  65. for(auto li: libraries){
  66. scoring();
  67. sort(libraries.begin(), libraries.end(), cmp);
  68. for(int i =0; i<l;i++){
  69. if(lt[libraries[i].first[4]]) continue;
  70. lt[libraries[i].first[4]] = 1;
  71. cout << libraries[i].first[4] << ' ' << libraries[i].first[0] << '\n';
  72. for(auto boo: libraries[i].second){
  73. cout << boo.second << " ";
  74. }
  75. cout << '\n';
  76. break;
  77. }
  78. }
  79.  
  80.  
  81.  
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement