-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA02006.cpp
More file actions
63 lines (60 loc) · 1.07 KB
/
Copy pathDSA02006.cpp
File metadata and controls
63 lines (60 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
int b[1000];
vector<int> c;
bool check;
void print()
{
cout << '[';
for(int i = 0; i<c.size(); i++)
{
cout << c[i];
if( i!= c.size() - 1) cout << ' ';
else
cout << "] ";
}
}
void Try(vector<int> &a, long long sum, int k, int pos)
{
for(int j = pos; j<a.size(); j++)
{
if(b[j] == 0)
{
sum += a[j];
c.push_back(a[j]);
b[j] = 1;
if(sum==k)
{
check = 1;
print();
}
else
{
Try(a, sum, k, j+1);
}
b[j] = 0;
sum -= a[j];
c.pop_back();
}
}
}
int main()
{
int t;
cin >> t;
while(t--)
{
check = 0;
int n, k;
cin >> n >> k;
vector<int> a(n);
for(int &i:a) cin >> i;
sort(a.begin(), a.end());
Try(a, 0, k, 0);
if(!check)
{
cout << "-1";
}
cout << endl;
}
}