#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define ins insert
#define F first
#define S second
#define MAXN 1000005
#define LOG (int)log2(MAXN)+1
const int INF = 1e18;
const int MOD = 998244353;
const double EPS = 1e-8;
//49p
void solve() {
int S, n;
cin >> S >> n;
if(n!=1){
vector<int> p(n), w(n), c(n);
for(int i = 0; i < n; i++) cin >> p[i] >> w[i] >> c[i];
vector<int> dp(S+1, 0);
for(int i = 0; i < n; i++){
for(int j = S; j >= w[i]; j--){
for(int k = 0; k<=c[i] && k*w[i]<=j; k++){
dp[j] = max(dp[j], dp[j-k*w[i]]+k*p[i]);
}
}
}
cout << dp[S] << '\n';
} else{
int p, w, k;
cin >> p >> w >> k;
cout << min(S/w, k)*p << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
//cout << "Case " << i << ": ";
solve();
}
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... |