bdfz_2024_summer/day13/P2871/P2871.cpp

41 lines
637 B
C++
Raw Normal View History

2024-08-16 02:51:09 +00:00
//AC
#include<bits/stdc++.h>
using namespace std;
const int MAX_M = 1'2880+5;
int dp[MAX_M],w[MAX_M],v[MAX_M];
int n,m;
int readint();
int main(){
n=readint();
m=readint();
for(int i=1;i<=n;i++){
w[i]=readint();
v[i]=readint();
}
for(int i=1;i<=n;i++){
for(int j=m;j>=w[i];j--){
dp[j]=max(dp[j-w[i]]+v[i],dp[j]);
}
}
cout<<dp[m]<<endl;
}
int readint(){
int x=0,w=1;
char ch =0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}