# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
652348 | chanhchuong123 | Knapsack (NOI18_knapsack) | C++14 | 1092 ms | 16176 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>
using namespace std;
#define task "C"
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int S = 2020;
int s, n;
long long dp[S];
vector<long long> v;
vector<long long> w;
main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> s >> n;
for (int i = 1; i <= n; i++) {
int V, W, K; cin >> V >> W >> K;
for (int i = 1; i <= K; i <<= 1) {
v.push_back(1LL * i * V);
w.push_back(1LL * i * W);
K -= i;
}
if (K) {
v.push_back(1LL * K * V);
w.push_back(1LL * K * W);
}
}
n = v.size();
for (int i = 0; i < n; i++) {
for (int j = s; j >= 0; j--) {
if (j + w[i] > s) continue;
maxi(dp[j + w[i]], dp[j] + v[i]);
}
}
cout << dp[s];
}
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... |