forked from Shubham28/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNOCHANGE.cpp
59 lines (47 loc) · 927 Bytes
/
NOCHANGE.cpp
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
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstring>
#define FOR(A,B,C) for(int A=B;A<C;A++)
#define EFOR(A,B,C) for(int A=B;A<=C;A++)
#define RFOR(A,B,C) for(int A=B;A>=C;A--)
#define VI vector<int>
#define SZ(A) int(A.size())
#define LL long long
using namespace std;
inline void Input(int &N)
{
int ch;
N=0;
while((ch<'0' || ch>'9') && ch!='-' && ch!=EOF)
ch=getchar();
do
N=(N<<3)+(N<<1)+(ch-'0');
while((ch=getchar())>='0' && ch<='9');
return;
}
int main()
{
int amt,N;
Input(amt),Input(N);
int coins[N+1];
bool posb[amt+2];
memset(posb,0,sizeof(posb));
FOR(inp,0,N){
int tmp;
Input(tmp);
coins[inp]=((inp>0)?coins[inp-1]:0)+tmp;
}
posb[0]=1;
FOR(all,0,amt){
for(int fill=0;fill<N && posb[all];fill++)
if(all+coins[fill]<=amt)
posb[all+coins[fill]]=posb[all];
}
if(posb[amt])
printf("YES\n");
else
printf("NO\n");
return 0;
}