# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1070428 | seoul_korea | Knapsack (NOI18_knapsack) | C++17 | 1 ms | 600 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;
using ll = long long;
const bool multiTest = 0;
#define TASK ""
mt19937 rng(time(0));
const int maxN = 2222;
struct Pack {
ll w, v;
};
ll totalW;
int n;
vector<Pack> packs;
ll dp[maxN];
void solve(int curTest) {
cerr << "\n>TEST #" << curTest << "<\n";
// GET AC PLEASE
cin >> totalW >> n;
for(int i = 1; i <= n; i++) {
int v, w, k;
cin >> v >> w >> k;
int phanTach = 1;
while(k - phanTach >= 0) {
packs.push_back({w * phanTach, v * phanTach});
k -= phanTach;
phanTach *= 2;
}
if(k > 0) packs.push_back({w * k, v * k});
}
memset(dp, -0x3f, sizeof dp);
dp[0] = 0;
for(auto pack : packs) {
for(ll s = totalW; s >= pack.w; s--) {
dp[s] = max(dp[s], dp[s - pack.w] + pack.v);
}
}
cout << *max_element(dp, dp + totalW + 1) << endl;
}
main() {
cin.tie(0)->ios_base::sync_with_stdio(0);
if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
if(fopen(TASK".INP", "r")) {
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
int nTest = 1;
if(multiTest) cin >> nTest;
for(int iTest = 1; iTest <= nTest; iTest++) solve(iTest);
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... |