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;
ll dp[S];
ll 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 ++){
ll v = value[i]; int w = weight[i], a = amount[i];
for (int j = s; j >= 0; j --){
for (int k = 1; k <= a; k ++){
if(j + k * w <= s) dp[j + k * w] = max(dp[j + k * w], dp[j] + k * v);
}
}
}
ll 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... |