Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int n;
- vector<bool> dp;
- vector<vector<int>> pr;
- vector<int> a, b, c;
- int current_mood(int mask)
- {
- int ans{0};
- for (int i = 0; i < n; ++i)
- ans += ((mask >> i) & 1) * c[i];
- return ans;
- }
- int main()
- {
- std::ios::sync_with_stdio(false);
- int k, mood;
- cin >> n >> k;
- int max_mask = (1 << n);
- dp.resize(max_mask);
- pr.resize(max_mask);
- a.resize(n); b.resize(n); c.resize(n);
- for (int i = 0; i < n; ++i)
- cin >> a[i] >> b[i] >> c[i];
- dp[0] = true;
- for (int mask = 0; mask < max_mask; ++mask) {
- if (!dp[mask])
- continue;
- mood = k + current_mood(mask);
- //cout << "MOOD: " << mood << endl;
- for (int i = 0; i < n; ++i) {
- if ((mask >> i) & 1)
- continue;
- if (mood >= a[i] && mood <= b[i]) {
- dp[mask | (1 << i)] = true;
- pr[mask | (1 << i)] = pr[mask];
- pr[mask | (1 << i)].push_back(i + 1);
- }
- else
- dp[mask | (1 << i)] = false;
- }
- }
- int ans = 0;
- for (int mask = 0; mask < max_mask; ++mask)
- if (dp[mask] && pr[mask].size() > pr[ans].size())
- ans = mask;
- cout << pr[ans].size() << '\n';
- for (const int& x : pr[ans])
- cout << x << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement