没平移价值,map卡过去了
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
typedef long long ll;
using namespace std;
const ll N = 410;
const ll MOD = 998244353;
int cowi[N],cowe[N];
int fi2[800010];
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
map<int,int>dp1;
dp1[0]=0;
for(int i=1;i<=n;i++)
{
cin>>cowi[i]>>cowe[i];
}
for(int i=1;i<=n;i++)
{
map<int,int>dp2,fi1;
for(auto it:dp1)
{
int I=it.first+cowi[i],E=it.second+cowe[i];
if(fi1[I]==0)
{
fi1[I]=1;
dp2[I]=E;
}
else dp2[I]=max(E,dp2[I]);
}
for(auto it:dp2)
{
if(fi2[it.first+400000]==0)
{
dp1[it.first]=it.second;
fi2[it.first+400000]=1;
}
else dp1[it.first]=max(it.second,dp1[it.first]);
}
}
int ans=0;
for(auto it:dp1)
{
if(it.first>=0&&it.second>=0) ans=max(it.first+it.second,ans);
}
cout<<ans;
}