# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1104970 | The_Eureka | Knapsack (NOI18_knapsack) | C++17 | 1092 ms | 19916 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define alls(x) x.begin(), x.end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, n) for (int i = 1; i <= int(n); i++)
#define sz(x) int(x.size())
#define dbg(x) cerr << #x << " = " << x << endl;
#define cin std::cin
#define cout std::cout
#define pii pair<int, int>
#define pll pair<ll, ll>ip
const ld eps = 1e-12;
const ll inf = 1e16;
const ll mod = 998244353;
const ll mod1 = 1e9 + 87;
const ll mod2 = 1e9 + 93;
using namespace std;
void IOS(string name = "") {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false); // see /general/fast-io
if (sz(name)) {
freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
freopen((name + ".out").c_str(), "w", stdout);
}
}
struct node {
ll w;
ll v;
};
int main() {
IOS();
int n, W;
cin >> W >> n;
vector<node> objects;
rep(i, n) {
int v, w, m;
cin >> v >> w >> m;
int c = 1;
while (m > c) {
m -= c;
objects.pb((node){1ll * w * c, 1ll * v * c});
c *= 2;
}
objects.pb((node){1ll * w * m, 1ll * v * m});
}
vector<ll> dp(W + 1, 0);
for (auto [w, v]: objects) {
for (int j = W; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << dp[W] << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |