Pagini recente » Cod sursa (job #2646734) | Cod sursa (job #1369177) | Cod sursa (job #1734163) | Cod sursa (job #568023) | Cod sursa (job #2916182)
/**
* author: R0L3eX
* created: 28.07.2022 11:22:37
* quote: Claustrophobic? Who would ever be afraid of Santa Clause?
**/
#include "bits/stdc++.h"
using namespace std;
#if defined(ONPC)
#include "bits/debug.h"
#endif
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> using matrix = vector<vector<T> >;
template<typename T> void Unique(T &a) {a.erase(unique(a.begin(), a.end()), a.end());}
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0);
if ((int)name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
const int MOD = 1e9 + 7;
const int mxN = 2e5;
const int INF = INT_MAX;
const char nl = '\n';
struct obj {
int W, P;
};
int main() {
setIO("rucsac");
int n, maxW;
cin >> n >> maxW;
vector<obj> v(n);
for (obj &x : v) {
cin >> x.W >> x.P;
}
matrix<int> dp(2, vector<int>(maxW + 1));
for (int i = 0; i < n; ++i) {
for (int w = 1; w <= maxW; ++w) {
dp[i%2][w] = dp[1-i%2][w];
if (v[i].W <= w) {
int add = 0, extra = w - v[i].W;
if (extra >= 0) {
add = dp[1-i%2][extra];
}
dp[i%2][w] = max(dp[i%2][w], add + v[i].P);
}
}
}
cout << max(dp[1][maxW], dp[0][maxW]) << nl;
}