#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define s second
#define int long long
#define pb push_back
#define f first
#define s second
const long long inf = 1e9 + 7;
const int N = 4e5 + 101;
void solve(){
int n,s;
cin >> s >> n;
if(n == 1){
int w,v,k;
cin >> v >> w >> k;
int ans = 0,sum = 0;
while(true){
if(sum + w > s || w > s || k == 0) break;
sum += w,ans += v,k--;
}
cout << ans;
return;
}
vector <pair<int,int>> v1;
for(int i = 1; i <= n; i++){
int w,v,k;
cin >> v >> w >> k;
for(int j = 1; j <= k; j++){
v1.pb({w,v});
}
}
vector <int> dp(s + 10,-inf);
dp[0] = 0;
for(int i = 0; i < v1.size(); i++){
//cout << v1[i].f << " " << v1[i].s << '\n';
for(int j = s; j >= v1[i].f; j--){
dp[j] = max(dp[j],dp[j - v1[i].f] + v1[i].s);
}
//cout << dp[s] << " ";
}
int mx = 0;
for(int i = 0; i <= s; i++) mx = max(mx,dp[i]);
cout << mx;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen("promote.in", "r", stdin);
//freopen("promote.out", "w", stdout);
int t = 1;
while(t--){
solve();
}
}
| # | 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... |