Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define sc second
- #define fi first
- using namespace std;
- const int N = 1001;
- const int INF = 1000009;
- pair <int, vector <int> > p[INF];
- int t[N], d[INF];
- int a, b, c, n;
- int main() {
- cin >> a >> b >> c >> n;
- if (a > c) {
- cout << -1;
- return 0;
- }
- for (int i = 1; i <= n; i++) {
- cin >> t[i];
- }
- // d[a] = 1;
- d[0] = 1;
- for (int i = 1; i <= n; i++) {
- for (int j = 2002; j >= 0; j--) {
- if (j + t[i] < 2002 && d[j] == 1) {
- d[j + t[i]] = 1;
- p[j + t[i]].fi = j;
- p[j + t[i]].sc.pb(i);
- }
- }
- }
- vector <int> v;
- for (int i = c - a + 1; i <= 2002; i++) {
- if (d[i] && i + a < (a + b)) {
- cout << i + a << "\n";
- int x = p[i].sc.back(), y = p[i].fi;
- // cout << x << " " << y << "\n";
- p[i].sc.pop_back();
- while (x) {
- // cout << "asdf";
- v.push_back(x);
- int y1 = y;
- if (p[y].sc.empty()) break;
- x = p[y].sc.back(), y = p[y].fi;
- p[y1].sc.pop_back();
- // cout << x << " " << y << "\n";
- }
- sort(v.begin(), v.end());
- cout << v.size() << " ";
- for (int i = 0; i < v.size(); i++)
- cout << v[i] << " ";
- return 0;
- }
- }
- cout << -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement