https://www.luogu.com.cn/problem/P2871
#include<bits/stdc++.h>
#define lc p<<1
#define rc p<<1|1
#define INF 2e9
using namespace std;
#define endl '\n'
using ll = long long;
using pii = pair<ll, ll>;
const double PI = acos(-1);
const int N = 4e3+ 10;
const int M=1e5;
int w[N],d[N];
//int f[N][M];
int f[M];
void solve(){
// int n,m;cin>>n>>m;
// for(int i=1;i<=n;i++){
// cin>>w[i]>>d[i];
// }
// for(int i=1;i<=n;i++)
// for(int j=0;j<=m;j++){
// if(w[i]>j){
// f[i][j]=f[i-1][j];
// }
// else{
// f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+d[i]);
// }
// }
// cout<<f[n][m];
int n,m;cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>w[i]>>d[i];
}
for(int i=1;i<=n;i++)
// for(int j=m;j>=0;j--){
// if(w[i]<=j)
// f[j]=max(f[j],f[j-w[i]]+d[i]);
for(int j=m;j>=w[i];j--){
f[j]=max(f[j],f[j-w[i]]+d[i]);
}
}
cout<<f[m];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
浙公网安备 33010602011771号