#include <iostream> #include <algorithm> using namespace std; int t[310]; int v[310]; long long f[310]; int main(){ int n,m; while(cin>>n>>m){ for(int i=1;i<=n;i++){ cin>>t[i]>>v[i]; } for(int i=1;i<=n;i++){ for(int j=m;j>=t[i];j--){ f[j]=max(f[j],f[j-t[i]]+v[i]); } } cout<<f[m]<<endl; } return 0; } |
Double click to view unformatted code.