Pagini recente » Cod sursa (job #1347715) | Cod sursa (job #2042421) | Cod sursa (job #1424820) | Cod sursa (job #1592000) | Cod sursa (job #3210988)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
struct obj{
int weight;
int profit;
};
const int N = 5e3 + 1;
const int G = 1e4 + 1;
obj v[N];
int dp[G];
//dp[weight] = max profit
int main() {
int n, g_max;
cin >> n >> g_max;
for (int i = 1; i <= n; ++i)
cin >> v[i].weight >> v[i].profit;
for (int i = 1; i <= n; ++i)
for (int j = g_max; j >= v[i].weight; --j)
dp[j] = max(dp[j], dp[j - v[i].weight] + v[i].profit);
int maxim = 0;
for (int i = 1; i <= g_max; ++i)
maxim = max(maxim, dp[i]);
cout << maxim;
return 0;
}