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 FOR(i, e) for (int i = 0; i < (e); i++)
#define FOR1(i, e) for (int i = 1; i <= (e); i++)
#define ull unsigned long long int
#define pii pair <int, int>
#define value first.first
#define weight first.second
#define quantity second
int n, s;
pair<pii, int> items[100000];
int dp[100001][2001];
int main(){
cin >> s >> n;
FOR(i, n){
cin >> items[i].value >> items[i].weight >> items[i].quantity;
}
FOR1(i, n) {
for (int j = 0; j <= s; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= items[i - 1].weight){
dp[i][j] = max(dp[i][j], dp[i - 1][j - items[i - 1].weight] + items[i - 1].value);
}
}
}
cout << dp[n][s];
return 0;
}
# | 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... |