Pagini recente » Cod sursa (job #2036329) | Cod sursa (job #725997) | Cod sursa (job #1899612) | Cod sursa (job #1496520) | Cod sursa (job #2156684)
#include <iostream>
#include <fstream>
#define dMAX 10001
using namespace std;
int n, capacity;
int weight, profit;
int a[dMAX];
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int main()
{
int i, j;
fin >> n >> capacity;
a[0] = 1;
for (i = 1; i <= n; i++) {
fin >> weight >> profit;
for (j = capacity - weight; j >= 0; j--) {
if (a[j] + profit > a[j + weight]) {
a[j + weight] = a[j] + profit;
}
}
}
profit = 0;
for (i = 0; i <= capacity; i++) {
if (a[i] > profit) {
profit = a[i];
}
}
fout << profit - 1;
return 0;
}