1 //It is made by Awson on 2017.11.5
2 #include <set>
3 #include <map>
4 #include <cmath>
5 #include <ctime>
6 #include <stack>
7 #include <queue>
8 #include <vector>
9 #include <string>
10 #include <cstdio>
11 #include <cstdlib>
12 #include <cstring>
13 #include <iostream>
14 #include <algorithm>
15 #define LL long long
16 #define Min(a, b) ((a) < (b) ? (a) : (b))
17 #define Max(a, b) ((a) > (b) ? (a) : (b))
18 #define Abs(x) ((x) < 0 ? (-(x)) : (x))
19 using namespace std;
20 const int N = 50;
21 const int M = 1000;
22
23 bool f[M+5][N+5], t, lt;
24 int n, b, m, c;
25
26 void work() {
27 scanf("%d%d%d", &n, &b, &m); t = 1; f[b][lt] = 1;
28 for (int i = 1; i <= n; i++) {
29 scanf("%d", &c);
30 for (int j = 0; j <= m; j++) {
31 f[j][t] = 0;
32 if (j-c >= 0) f[j][t] |= f[j-c][lt];
33 if (j+c <= m) f[j][t] |= f[j+c][lt];
34 }
35 swap(t, lt);
36 }
37 for (int i = m; i >= 0; i--) if (f[i][lt]) {
38 printf("%d\n", i); return;
39 }
40 printf("%d\n", -1);
41 }
42 int main() {
43 work();
44 return 0;
45 }