Pagini recente » Monitorul de evaluare | Cod sursa (job #1937802) | Cod sursa (job #1020974) | Cod sursa (job #1604775) | Cod sursa (job #1625131)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream gi("rucsac.out");
int n,gmax,g,cost;
int mat[5000][10000];
void citire()
{
f>>n;
f>>gmax;
for(int i=1;i<=n;i++)
{
f>>g>>cost;
for(int j=g;j<=gmax;j++)
{
mat[j][i]=cost+mat[j-g][i-1];
if(mat[j][i]<mat[j][i-1])
{
mat[j][i]=mat[j][i-1];
}
}
}
gi<<mat[gmax][n];
}
int main()
{
citire();
return 0;
}