-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathoperation_on_array.cpp
More file actions
58 lines (48 loc) · 992 Bytes
/
Copy pathoperation_on_array.cpp
File metadata and controls
58 lines (48 loc) · 992 Bytes
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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
int t,n,k,a,b;
cin>>t;
while(t--)
{
cin>>n>>k;
queue<int> first;
cin>>a;
cin>>b;
first.push(a+b);
first.push(a-b);
n-=2;
while(n--)
{
cin>>a;
int j=first.size();
while(j--)
{
int p=first.front();
first.pop();
first.push(p+a);
first.push(p-a);
}
}
int flag=0;
while(!first.empty())
{
int p = first.front();
if(p==k)
{
flag=1;
cout<<"YES\n";
break;
}
first.pop();
}
if(flag==0)
cout<<"NO";
}
return 0;
}