Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. vector <int> num, now;
  7. vector <vector<int> > ans;
  8. int n;
  9.  
  10. vector <int> rev(vector <int> num) {
  11. vector <int> res;
  12. for (int i = num.size() - 1; i > -1; i--) {
  13. res.push_back(num[i]);
  14. }
  15. return res;
  16. }
  17.  
  18. void a(int pos, int sum) {
  19. if (sum == n) {
  20. //cout << "aaaaaaaaaaaaaaaaaa\n";
  21. ans.push_back(now);
  22. }
  23. else if (sum > n) {
  24. //cout << "bbbbbbbbbbbbbbbbb\n";
  25. return;
  26. }
  27. else {
  28. for (int i = pos + 1; i < num.size(); i++) {
  29. //cout << "jfdsifhusd\n";
  30. now.push_back(num[i]);
  31. a(i, sum + num[i]);
  32. now.pop_back();
  33. }
  34. }
  35. }
  36.  
  37. int32_t main() {
  38. int m;
  39. cin >> n >> m;
  40. int k = 0;
  41. for (int i = 0; i < m; i++) {
  42. int a;
  43. cin >> a;
  44. num.push_back(a);
  45. num.push_back(a);
  46. k += a * 2;
  47. }
  48. if (k < n) {
  49. cout << -1 << "\n";
  50. return 0;
  51. }
  52.  
  53. num = rev(num);
  54. //for (int i = 0; i < num.size(); i++) cout << num[i] << " ";
  55. //cout << "\n";
  56. a(-1, 0);
  57. if (ans.size() == 0) {
  58. if (k >= n) {
  59. cout << 0 << "\n";
  60. return 0;
  61. }
  62. cout << -1 << "\n";
  63. return 0;
  64. }
  65. cout << ans[0].size() << " ";
  66. for (int i = 0; i < ans[0].size(); i++) {
  67. cout << ans[0][i] << " ";
  68. }
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement