Advertisement
From_Earth_to_Mars

Untitled

Feb 20th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. typedef long long ll;
  4.  
  5. using namespace std;
  6. struct st{
  7.     int n, t, m;
  8.     vector<int> l;
  9.     st () : n(0), t(0), m(0), l(0) {};
  10. };
  11. int b, l, d, ans = 0, currd = 0;
  12. vector<int> ba;
  13. vector<st> la;
  14. set<int> used_b, used_l;
  15. vector<int> sum_l;
  16. vector<int> res;
  17. vector<vector<int>> res2;
  18. void upd(){
  19.     sum_l.assign(0, l);
  20.     for (int i = 0; i < l; ++i){
  21.         for (int &j : la[i].l){
  22.             if (used_b.find(j) == used_b.end()){
  23.                 sum_l[i] += ba[j];
  24.             }
  25.         }
  26.     }
  27. }
  28.  
  29. bool pick(){
  30.     int ma = 0, ind = -1;
  31.     for (int i  = 0; i < l; ++i){
  32.         if (used_l.find(i) != used_l.end()) continue;
  33.         if (sum_l[i] > ma){
  34.             ma = sum_l[i];
  35.             ind = i;
  36.         }
  37.     }
  38.     if (ind != -1){
  39.         used_l.insert(ind);
  40.         currd += la[ind].t;
  41.         res.push_back(ind);
  42.         int t = d-currd;
  43.         for (int i = 0; i < min((int)la[ind].l.size(), t); ++i){
  44.             int tmp = la[ind].l[i];
  45.             used_b.insert(tmp);
  46.             res2[ind].push_back(tmp);
  47.             ans += ba[tmp];
  48.         }
  49.         return true;
  50.     }
  51.     else return false;
  52. }
  53.  
  54.  
  55. signed main(){
  56.     ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr);
  57.     cin >> b >> l >> d;
  58.     ba.resize(b);
  59.     sum_l.resize(l);
  60.     for (int i = 0; i < b; ++i) {
  61.         cin >> ba[i];
  62.     }
  63.     la.resize(l);
  64.     res2.resize(l);
  65.     for (int i = 0; i < l; ++i) {
  66.         cin >> la[i].n >> la[i].t >> la[i].m;
  67.         la[i].l.resize(la[i].n);
  68.         for (int j = 0; j < la[i].n; ++j){
  69.             cin >> la[i].l[j];
  70.         }
  71.         sort(la[i].l.rbegin(), la[i].l.rend());
  72.     }
  73.     upd();
  74.     while (pick()){
  75.         upd();
  76.     }
  77.     cout << res.size() << '\n';
  78.     for (int i = 0; i < res.size(); ++i){
  79.         cout << res[i] << ' ' << res2[i].size() << '\n';
  80.         for (int &j : res2[i]) cout << j << ' ';
  81.         cout << '\n';
  82.     }
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement