#include <bits/stdc++.h>
using namespace std;
long long dp[2020], sp[2020];
int N, S;
int main() {
cin >> S >> N;
for(int i = 0; i < N; i++) {
int p, w, n;
cin >> p >> w >> n;
swap(dp, sp);
for(int x = 1; x <= S; x++) {
dp[x] = max(dp[x], sp[x]);
for(int t = 1; t <= n; t++) {
long long W = 1LL * w * t;
long long P = 1LL * p * t;
if(x >= W)
dp[x] = max(dp[x], sp[x - W] + P);
}
dp[x] = max(dp[x], dp[x - 1]);
}
}
cout << dp[S] << endl;
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... |