题解:
简单dp
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=;
int n,x,m,a[N],f[N][N];
int main()
{
scanf("%d%d%d",&n,&x,&m);
for (int i=;i<=n;i++)scanf("%d",&a[i]);
f[][x]=;
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
{
if (j+a[i]<=m&&f[i-][j+a[i]])f[i][j]=;
if (j-a[i]>=&&f[i-][j-a[i]])f[i][j]=;
}
for (int i=m;i>=;i--)
if (f[n][i]){printf("%d",i);return ;}
printf("-1");
return ;
}