Advertisement
Guest User

Untitled

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