Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- vector <int> num, now;
- vector <vector<int> > ans;
- int n;
- vector <int> rev(vector <int> num) {
- vector <int> res;
- for (int i = num.size() - 1; i > -1; i--) {
- res.push_back(num[i]);
- }
- return res;
- }
- void a(int pos, int sum) {
- if (sum == n) {
- //cout << "aaaaaaaaaaaaaaaaaa\n";
- ans.push_back(now);
- }
- else if (sum > n) {
- //cout << "bbbbbbbbbbbbbbbbb\n";
- return;
- }
- else {
- for (int i = pos + 1; i < num.size(); i++) {
- //cout << "jfdsifhusd\n";
- now.push_back(num[i]);
- a(i, sum + num[i]);
- now.pop_back();
- }
- }
- }
- int32_t main() {
- int m;
- cin >> n >> m;
- int k = 0;
- for (int i = 0; i < m; i++) {
- int a;
- cin >> a;
- num.push_back(a);
- num.push_back(a);
- k += a * 2;
- }
- if (k < n) {
- cout << -1 << "\n";
- return 0;
- }
- num = rev(num);
- //for (int i = 0; i < num.size(); i++) cout << num[i] << " ";
- //cout << "\n";
- a(-1, 0);
- if (ans.size() == 0) {
- if (k >= n) {
- cout << 0 << "\n";
- return 0;
- }
- cout << -1 << "\n";
- return 0;
- }
- cout << ans[0].size() << " ";
- for (int i = 0; i < ans[0].size(); i++) {
- cout << ans[0][i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement