Pagini recente » Cod sursa (job #3148283) | Cod sursa (job #1665081) | Cod sursa (job #2460613) | Cod sursa (job #2415899) | Cod sursa (job #3277473)
#include <bits/stdc++.h>
std::ifstream fin("rucsac.in");
std::ofstream fout("rucsac.out");
const int SIZE = 5e3 + 5;
const int MAXWEIGHT = 1e4 + 5;
int n, W;
int profit[SIZE], weight[SIZE];
int dp[MAXWEIGHT];
int ans;
int64_t max(std::vector<int64_t> v){ return *std::max_element(v.begin(), v.end()); }
int64_t min(std::vector<int64_t> v){ return *std::min_element(v.begin(), v.end()); }
int main()
{
fin >> n >> W;
for(int i = 1; i <= n; ++i)
fin >> weight[i] >> profit[i];
for(int i = 1; i <= n; ++i)
for(int j = W - weight[i]; j >= 0; --j)
{
dp[j + weight[i]] = std::max(dp[j + weight[i]], dp[j] + profit[i]);
ans = std::max(ans, dp[j + weight[i]]);
}
fout << ans;
return 0;
}