#include #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair; int main(){ int n, m; cin>>n>>m; vector a(n); rep(i, n) cin>>a[i]; sort(a.rbegin(), a.rend()); m++; vector dp(m), ndp(m); map sp; sp[0]=INT_MIN/3; auto upd=[](int &a, int b){ a=max(a, b); }; rep(i, n){ { rep(j, m) ndp[j]=dp[j]; auto nt=sp.upper_bound(a[i]); auto it=nt; it--; rep(j, m){ while(nt!=sp.end() && (nt->first)<=a[i]+j){ it++; nt++; } upd(ndp[j], it->second); } } rep(j, m){ int x=j+a[i], y=dp[j]+a[i]; auto rt=sp.upper_bound(x); auto lt=rt; lt--; if((lt->second)>=y) continue; vector::iterator> dl; for(; rt!=sp.end() && (rt->second)<=y; rt++){ dl.push_back(rt); } for(auto it : dl) sp.erase(it); sp[x]=y; } swap(dp, ndp); } cout<