-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1068.cpp
46 lines (44 loc) · 1.1 KB
/
1068.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
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define MAX_N 55
#define MAX_K 205
#define MAX_VALUE 2000005
using namespace std;
queue<int> q;
bool d[MAX_VALUE];
int val[MAX_N];
int n, k;
inline int read() {
char ch = getchar(); int res = 0, flag = 1;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') flag = -1, ch = getchar();
while (ch >= '0' && ch <= '9')
res = res * 10 + ch - '0', ch = getchar();
return res;
}
int main() {
k = read(); n = read();
for (int i = 0; i < n; ++i) val[i] = read();
q.push(0);
for (int i = 1; i <= k; ++i) {
int cnt = q.size();
for (int x = 0; x < cnt; ++x) {
int v = q.front(); q.pop();
for (int j = 0; j < n; ++j) {
int v_tmp = v + val[j];
if (!d[v_tmp]) {
q.push(v_tmp);
d[v_tmp] = true;
}
}
}
}
for (int i = 1; i < MAX_VALUE; ++i)
if (!d[i]) {
printf("%d\n", i - 1);
break;
}
return 0;
}