# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464292 | vbee | Knapsack (NOI18_knapsack) | C++14 | 1094 ms | 1420 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 all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>
#define fi first
#define se second
#define TASK ""
#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define pb push_back
#define MASK(i) (1 << (i))
#define BIT(x, i) ((x >> (i)) & 1)
using namespace std;
const int oo = 1e9 + 7;
const ll loo = (ll)1e18 + 7;
const int N = 1e5 + 1;
const int S = 2001;
int dp[S], newdp[S], w[N], v[N], k[N], n, s;
void maximize(int &a, int b){
if (a < b) a = b;
}
int main() {
scanf("%d%d", &s, &n);
for (int i = 1; i <= n; i++) scanf("%d%d%d", &v[i], &w[i], &k[i]);
for (int i = 0; i < n; i++){
for (int sum = 0; sum <= s; sum++){
for (int z = 0; z <= k[i + 1]; z++){
if (sum + w[i + 1] * z > s) break;
maximize(dp[sum + w[i + 1] * z], newdp[sum] + v[i + 1] * z);
}
swap(dp[sum], newdp[sum]);
dp[sum] = 0;
}
}
int res = 0;
for (int i = 0; i <= s; i++) maximize(res, newdp[i]);
printf("%d", res);
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... |