# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
951585 | SamNguyen | Knapsack (NOI18_knapsack) | C++14 | 1068 ms | 2904 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 FNAME "test"
typedef long long ll;
const int N = 1e5 + 5;
const int W = 2005;
int n, w;
int v[N], m[N], c[N];
ll dp[W];
void Task() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(9);
if (fopen(FNAME".inp","r")) {
freopen(FNAME".inp","r",stdin);
freopen(FNAME".out","w",stdout);
}
}
void Solve() {
//Your Code
cin >> w >> n;
for (int i = 1; i <= n; i++) cin >> v[i] >> m[i] >> c[i];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = w; j >= m[i]; j--) {
for (int k = 1; (k * m[i] <= j) && (k <= c[i]); k++) {
dp[j] = max(dp[j], dp[j - k * m[i]] + 1LL * k * v[i]);
}
}
}
cout << dp[w] << '\n';
}
int main() {
Task();
Solve();
cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms";
return 37^37;
}
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... |