#include using namespace std; #ifdef _DEBUG #include "_DEBUG.hpp" #endif #define int long long const long long inf = 2e18; const int mod = 1e9 + 7; template istream &operator>>(istream &is, vector &v) { for (T &in : v) is >> in; return is; } template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } template typename enable_if::value == 0>::type fill(T &t, const V &v) { t = v; } template typename enable_if::value != 0>::type fill(T &t, const V &v) { for (auto &e : t) fill(e, v); } signed main() { int n, m; cin >> n >> m; vector a(n); cin >> a; sort(a.rbegin(), a.rend()); auto dp = make_vec(n + 1, m + 1); fill(dp, -inf); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= m; j++) { if (i + 2 <= n && j + a[i] - a[i + 1] <= m) dp[i + 2][j + a[i] - a[i + 1]] = max(dp[i + 2][j + a[i] - a[i + 1]], dp[i][j] + a[i]); dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } int ans = *max_element(dp[n].begin(), dp[n].end()); cout << ans << endl; return 0; }