Pagini recente » Cod sursa (job #159763) | Cod sursa (job #2371521) | Cod sursa (job #1499) | Cod sursa (job #1165493) | Cod sursa (job #1668521)
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n,i,j,gr,mx,x,y,b[10001];
int main()
{
f >> n >> gr;
f >> x >> y;
b[x] = y;
for(i = 2; i <= n; ++i)
{
f >> x >> y;
for(j = gr - x; j >= 0; --j)
if(b[j] > 0)
if(b[j + x] == 0 || b[j + x] < b[j] + y)
b[j + x] = b[j] + y;
if(b[x] == 0 || b[x] < y)
b[x] = y;
}
mx = 0;
for(i = 1; i <= gr; ++i)
if(b[i] > mx)
mx = b[i];
g << mx << '\n';
return 0;
}