1 #include<bits/stdc++.h>
2 using namespace std;
3 int c[55],f[55][1010];
4 int read()
5 {
6 int s=0,fh=1;char ch=getchar();
7 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)fh=-1;ch=getchar();}
8 while(ch>=‘0‘&&ch<=‘9‘){s=s*10+(ch-‘0‘);ch=getchar();}
9 return s*fh;
10 }
11 int main()
12 {
13 freopen("changingsounds.in","r",stdin);
14 freopen("changingsounds.out","w",stdout);
15 int n,begin,mx,i,j;
16 n=read();begin=read();mx=read();
17 for(i=1;i<=n;i++)c[i]=read();
18 memset(f,0,sizeof(f));//f[i][j]第i个时间,音量为j是否可能.
19 f[0][begin]=1;
20 for(i=1;i<=n;i++)
21 {
22 for(j=0;j<=mx;j++)
23 {
24 if(j-c[i]>=0&&f[i-1][j-c[i]]==1)f[i][j]=1;
25 if(j+c[i]<=mx&&f[i-1][j+c[i]]==1)f[i][j]=1;
26 }
27 }
28 for(i=mx;i>=0;i--)if(f[n][i]==1)break;
29 if(i>=0)printf("%d",i);
30 else printf("-1");
31 fclose(stdin);
32 fclose(stdout);
33 return 0;
34 }