#include #include int max(int a, int b) { if (a > b) return a; return b; } int main(void) { int N, K, A[20]; scanf("%d%d", &N, &K); for (int i = 0; i < N; ++i) scanf("%d", &A[i]); int **dp = malloc(sizeof(int*) * (N + 1)); for (int i = 0; i <= N; ++i) dp[i] = malloc(sizeof(int) * (K + 1)); for (int i = 0; i <= K; ++i) dp[0][i] = 0; for (int i = 1; i <= N; ++i) { for (int j = 0; j <= K; ++j) { if (A[i - 1] <= j) dp[i][j] = max(A[i - 1] + dp[i - 1][j - A[i - 1]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } printf("%d", dp[N][K]); for (int i = 0; i <= N; ++i) free(dp[i]); free(dp); return 0; }