#include using namespace std; int dp[3001][3001]; int main() { int N, M; cin >> N >> M; vector A(N); for(int i = 0; i < N; i++) { cin >> A[i]; } sort(A.begin(), A.end()); for(int i = 1; i <= N; i++) { for(int j = 0; j <= M; j++) { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); if(i >= 2 && A[i - 1] - A[i - 2] <= j) dp[i][j] = max(dp[i][j], A[i - 1] + dp[i - 2][j - (A[i - 1] - A[i - 2])]); } } cout << dp[N][M] << "\n"; }