//#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; using pii = pair; using pll = pair; using pli = pair; #define TEST cerr << "TEST" << endl #define AMARI 998244353 //#define AMARI 1000000007 #define el '\n' #define El '\n' #define YESNO(x) ((x) ? "Memo" : "Numo") #define YES YESNO(true) #define NO YESNO(false) #define REV_PRIORITY_QUEUE(tp) priority_queue,greater> #define NO_ANS(x) {cout << (x) << '\n'; return;} template void inline VEC_UNIQ(vector &v){ sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return; } #define MULTI_TEST_CASE false void solve(void){ //問題を見たらまず「この問題設定から言えること」をいっぱい言う //一個回答に繋がりそうな解法が見えても、実装や細かい詰めに時間がかかりそうなら別の方針を考えてみる //ある程度考察しても全然取っ掛かりが見えないときは実験をしてみる //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く //複数の解法のアイデアを思いついた時は全部メモしておく //g++ -D_GLIBCXX_DEBUG -Wall -Wextra -O2 c.cpp -o o int n,m; cin >> n >> m; vector> cd(n); for(int i = 0; i < n; i++){ cin >> cd[i].first >> cd[i].second; } sort(cd.begin(),cd.end()); //dp[i] = コストの総和がiの時の最大ダメージ vector dp(m + 1,-1LL); dp[0] = 0LL; for(int i = 0; i < n; i++){ vector ndp = dp; ll c,d; tie(c,d) = cd[i]; for(int j = 0; 2LL * j + c <= m; j++){ if(dp[j] == -1LL)continue; ndp[2LL * j + c] = max(ndp[2LL * j + c],dp[j] + d); } swap(dp,ndp); } cout << *max_element(dp.begin(),dp.end()) << el; return; } void calc(void){ return; } signed main(void){ cin.tie(nullptr); ios::sync_with_stdio(false); calc(); int t = 1; if(MULTI_TEST_CASE)cin >> t; while(t--){ solve(); } return 0; }