# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088610 | shidou26 | Knapsack (NOI18_knapsack) | C++14 | 14 ms | 5724 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 endl '\n'
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int N = 1e5 + 3;
int n, m;
int num = 0;
ll dp[N], wes[N], ves[N];
void prepare() {
}
void input() {
cin >> m >> n;
for(int i = 1; i <= n; i++) {
int w, v, a; cin >> v >> w >> a;
int two = 1;
while(two <= a) {
wes[++num] = 1LL * w * two;
ves[num] = 1LL * v * two;
a -= two;
two *= 2;
}
if(a > 0) {
wes[++num] = 1LL * w * a;
ves[num] = 1LL * v * a;
}
}
}
void process() {
for(int i = 1; i <= num; i++) {
for(int j = m; j >= wes[i]; j--) {
dp[j] = max(dp[j], dp[j - wes[i]] + ves[i]);
}
}
cout << dp[m] << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#define task "quantity"
if(fopen(task".INP", "r")) {
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
prepare();
int testcase = 1; // cin >> testcase;
for(int i = 1; i <= testcase; i++) {
input();
process();
}
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... |