#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 1;
#define nl "\n"
#define sp " "
int s, n, w[N], v[N], k[N];
void subtask4(){
int dp[n+1][s+1];
memset(dp, 0, sizeof dp);
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;
}
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];
subtask4();
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... |