# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103904 | micro7 | Knapsack (NOI18_knapsack) | C++17 | 1 ms | 424 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 <algorithm>
#include <cstdio>
using namespace std;
constexpr int MAXN = 1e5, MAXS = 2000;
int n;
long long s;
long long dp[MAXS + 1];
void add_01_item(long long v, long long w) {
for (int i = s; i >= w; --i)
dp[i] = max(dp[i], dp[i - s] + v);
}
int main() {
scanf("%lld%d", &s, &n);
while (n--) {
long long v, w, k;
scanf("%lld%lld%lld", &v, &w, &k);
for (int i = 1; i <= k; i *= 2) {
add_01_item(v * i, w * i);
k -= i;
}
if (k)
add_01_item(v * k, w * k);
}
printf("%lld", dp[s]);
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... |