Pagini recente » Cod sursa (job #505793) | Cod sursa (job #2746747) | Cod sursa (job #1906941) | Cod sursa (job #2664025) | Cod sursa (job #3294782)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int dp[10005];
int n,greutate_maxima;
int maxim=0;
int main()
{
fin>>n>>greutate_maxima;
for(int i=0;i<n;i++)
{
int pret,greutate;
fin>>greutate>>pret;
for(int j=greutate_maxima-greutate; j>=0; j--)
{
if(dp[j]+pret>dp[j+greutate])
{
dp[j+greutate]=dp[j]+pret;
}
}
for(int i=0;i<=greutate_maxima;i++)
{
maxim=max(maxim,dp[i]);
}
}
fout<<maxim;
}