Advertisement
From_Earth_to_Mars

Untitled

Feb 20th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 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. inline 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. inline 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); cout.tie(0); cin.tie(0); cerr.tie(0);
  61.     ifstream cin; cin.open("d_tough_choices.txt");
  62.     ofstream cout; cout.open("d_tough_choices.out");
  63.     cin >> b >> l >> d;
  64.     ba.resize(b);
  65.     sum_l.resize(l);
  66.     for (int i = 0; i < b; ++i) {
  67.         cin >> ba[i];
  68.     }
  69.     la.resize(l);
  70.     res2.resize(l);
  71.     for (int i = 0; i < l; ++i) {
  72.         cin >> la[i].n >> la[i].t >> la[i].m;
  73.         la[i].l.resize(la[i].n);
  74.         for (int j = 0; j < la[i].n; ++j){
  75.             cin >> la[i].l[j];
  76.         }
  77.         sort(la[i].l.rbegin(), la[i].l.rend());
  78.     }
  79.     upd();
  80.     while (pick()){
  81.         upd();
  82.     }
  83.     int cnt_ans = 0;
  84.     for (int i = 0; i < res.size(); i++) {
  85.         if (!res2[i].empty()) cnt_ans++;
  86.     }
  87.     cout << cnt_ans << '\n';
  88.     for (int i = 0; i < res.size(); ++i){
  89.         if (res2[i].empty()) continue;
  90.         cout << res[i] << ' ' << res2[i].size() << '\n';
  91.         for (int &j : res2[i]) cout << j << ' ';
  92.         cout << '\n';
  93.     }
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement