#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 1;
const int S = 2e3 + 1;
#define nl "\n"
#define sp " "
int s, n, w[N], v[N], k[N], dp[N][S];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s >> n;
for(int i = 1; i<=n; i++) cin >> v[i] >> w[i] >> k[i];
for(int i = 0; i<=s; i++){
for(int j = 1; j<=n; j++){
dp[j][i] = dp[j-1][i];
for(int g = 0; g<=k[j]; g++){
if(w[j]*g > i) break;
dp[j][i] = max(dp[j][i], dp[j-1][i-w[j]*g] + v[j]*g);
}
}
} 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... |