boiduonghsg7
Rating
-
Bài tập
3
Điểm
1434
Rating #
-
Điểm #
17309
Giới thiệu
include<string.h>
using namespace std;
define ll long long
ll n,k;
ll a[100];ll b[100];
ll f[100][100];
void qhd()
{
memset(f,0,sizeof(f));
for (ll i=1;i<=n;i++)
for (ll j=1;j<=k;j++)
{ f[i][j]=f[i-1][j];
if (j>=a[i])
f[i][j]=max(f[i][j],f[i-1][j-a[i]]+b[i]);
}
/* for (ll i=0;i<=n;i++)
{
for (ll j=0;j<=k;j++)
cout<<f[i][j]<<" ";
cout<<endl;
}*/
cout<<f[n][k];
}
int main()
{
ios_base::sync_with_stdio();cin.tie();cout.tie();
freopen("valy.inp","r",stdin);
// freopen("valy.inp","w",stdout);
freopen("valy.out","w",stdout);
cin>>n>>k;
for (ll i=1;i<=n;i++)
cin>>a[i]>>b[i];
qhd();
}