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 ll long long
const int N = 1e5 + 5;
const int S = 2005;
int dp[S];
int value[N];
int weight[N];
int amount[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, s;
cin >> s >> n;
for (int i = 0; i < n; i ++) cin >> value[i] >> weight[i] >> amount[i];
for (int i = 0; i < n; i ++){
int v = value[i], w = weight[i], a = amount[i];
for (int j = s - w; j >= 0; j --){
for (int k = 1; k <= min(a, (s - j) / w); k ++){
dp[j + k * w] = max(dp[j + k * w], dp[j] + k * v);
}
}
}
int ans = 0;
for (int i = 0; i <= s; i ++) ans = max(ans, dp[i]);
cout << ans << "\n";
}
# | 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... |