HUST Online Judge WebBoard
Problem 1362 >> map硬dp
20220440216 @ 2024-07-26 21:31:52
[ Quote ] [ Edit ] [ Delete ] 1#
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<unordered_map>
#include<map>
#include<vector>
#include<set>
//#include<bits/stdc++.h>
#define T int TT;cin>>TT;while (TT--)
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ref(i,n) for(ll i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
const ll LNF = 9223372036854775807;
using namespace std;
ll n, m, k, ans, cnt = 1;
typedef pair<ll, ll>tt;
const ll M = 1e5+10;
int main()
{
IOS;
cin>>n>>m;
map<ll,ll>ok;
ok[0]=0;
rep(i,n)
{
map<ll,ll>pk;
ll a,b;cin>>a>>b;
for(auto [c,d]:ok)
{
if(c+a<=m)
{
if(ok.find(c+a)!=ok.end())
pk[c+a]=max(ok[c+a],d+b);
else
pk[c+a]=d+b;
}
pk[c]=max(d,pk[c]);
}
ok=pk;
}
for(auto [a,b]:ok)
{
ans=max(ans,b);
}
cout<<ans;

}