Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- typedef long long ll;
- using namespace std;
- struct st{
- int n, t, m;
- vector<int> l;
- st () : n(0), t(0), m(0), l(0) {};
- };
- int b, l, d, ans = 0, currd = 0;
- vector<int> ba;
- vector<st> la;
- set<int> used_b, used_l;
- vector<int> sum_l;
- vector<int> res;
- vector<vector<int>> res2;
- inline void upd(){
- sum_l.assign(l, 0);
- for (int i = 0; i < l; ++i){
- for (int &j : la[i].l){
- if (used_b.find(j) == used_b.end()){
- sum_l[i] += ba[j];
- }
- }
- }
- }
- inline bool pick(){
- int ma = 0, ind = -1;
- for (int i = 0; i < l; ++i){
- if (used_l.find(i) != used_l.end()) continue;
- if (sum_l[i] > ma){
- ma = sum_l[i];
- ind = i;
- }
- }
- if (ind != -1){
- used_l.insert(ind);
- currd += la[ind].t;
- res.push_back(ind);
- int t = d-currd;
- for (int i = 0; i < min((int)la[ind].l.size(), t); ++i){
- int tmp = la[ind].l[i];
- if (used_b.find(tmp) != used_b.end()) continue;
- used_b.insert(tmp);
- res2[ind].push_back(tmp);
- ans += ba[tmp];
- }
- return true;
- }
- else return false;
- }
- signed main(){
- ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cerr.tie(0);
- ifstream cin; cin.open("d_tough_choices.txt");
- ofstream cout; cout.open("d_tough_choices.out");
- cin >> b >> l >> d;
- ba.resize(b);
- sum_l.resize(l);
- for (int i = 0; i < b; ++i) {
- cin >> ba[i];
- }
- la.resize(l);
- res2.resize(l);
- for (int i = 0; i < l; ++i) {
- cin >> la[i].n >> la[i].t >> la[i].m;
- la[i].l.resize(la[i].n);
- for (int j = 0; j < la[i].n; ++j){
- cin >> la[i].l[j];
- }
- sort(la[i].l.rbegin(), la[i].l.rend());
- }
- upd();
- while (pick()){
- upd();
- }
- int cnt_ans = 0;
- for (int i = 0; i < res.size(); i++) {
- if (!res2[i].empty()) cnt_ans++;
- }
- cout << cnt_ans << '\n';
- for (int i = 0; i < res.size(); ++i){
- if (res2[i].empty()) continue;
- cout << res[i] << ' ' << res2[i].size() << '\n';
- for (int &j : res2[i]) cout << j << ' ';
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement