Pagini recente » Cod sursa (job #2326975) | Cod sursa (job #3033131) | Cod sursa (job #928888) | Cod sursa (job #2443108) | Cod sursa (job #1689100)
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n,G;
int v[5002],g[5002],dp[10002];
int main()
{
fin >> n >> G ;
for(int i = 1 ; i <= n ; ++i )
fin >> g[i] >> v[i];
for( int i = 1 ; i <= n ; ++i )
for( int j = G ; j >= g[i] ; --j )
dp[j] = max( dp[j] , dp[ j - g[i] ] + v[i] );
fout << dp[G] ;
return 0;
}