Pagini recente » Cod sursa (job #988408) | Cod sursa (job #1430437) | Cod sursa (job #1845037) | Cod sursa (job #1981309) | Cod sursa (job #2854432)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
/* clang-format off */
#ifdef CLOCAL
#include <fmt/core.h>
#include <fmt/ranges.h>
using fmt::print;
#endif
static __attribute__((unused)) void redir(const std::string str) { std::freopen((str + ".in").c_str(), "r", stdin); std::freopen((str + ".out").c_str(), "w", stdout); }
static void fast_io() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); }
template<typename T> static void read(T& var) { std::cin >> var; }
template<typename T, typename... Ts> static void read(T& var, Ts&... vars) { read(var); read(vars...); }
template<typename Container, typename Key> static bool contains(const Container& cont, const Key& key) { return cont.find(key) != cont.end(); }
template<typename T> static void prt(const T& var) { std::cout << var; }
template<typename T, typename... Ts> static void prt(const T& var, const Ts&... vars) { prt(var); prt(vars...); }
using i64 = std::int64_t;
/* clang-format on */
int main()
{
redir("rucsac");
fast_io();
i64 n, x;
read(n, x);
std::vector<i64> prices;
std::vector<i64> npages;
for(i64 i = 0; i < n; ++i)
{
i64 a, b;
read(a, b);
prices.push_back(a);
npages.push_back(b);
}
std::vector<i64> dp(x + 1, 0);
for(i64 i = 1; i <= n; ++i)
{
for(i64 w = x; w >= 0; --w)
{
const i64 cprice = prices[i - 1];
const i64 cpages = npages[i - 1];
if(cprice <= w)
{
dp[w] = std::max(dp[w], cpages + dp[w - cprice]);
}
}
}
prt(dp[x], '\n');
}