#include #include #include #include #include #include #include #include #include #include #define mkp make_pair #define mkt make_tuple #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; template void chmin(T &a, const T &b) { if (a > b) a = b; } template void chmax(T &a, const T &b) { if (a < b) a = b; } const ll INF = 1e18; void solve() { int N, M; cin >> N >> M; vector A(N); rep(i, N) cin >> A[i]; sort(all(A)); reverse(all(A)); vector> dp(N + 1, vector(M + 1, -INF)); dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= M; j++) { ll value = dp[i][j]; if (value == -INF) continue; chmax(dp[i + 1][j], value); if (i + 2 <= N && j + A[i] - A[i + 1] <= M) chmax(dp[i + 2][j + A[i] - A[i + 1]], value + A[i]); } } ll ans = *max_element(all(dp[N])); cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }