#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=1e5+5;
const ll MAXS=2005;
ll s, n, v[MAXN], w[MAXN], k[MAXN], dp[MAXS], ans;
vector<pair<ll, ll>> vals[MAXS];
void dodp(ll vx, ll wx)
{
for (int i=s; i>=wx; i--)
{
dp[i]=max(dp[i], dp[i-wx]+vx);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> s >> n;
for (int i=0; i<n; i++)
{
cin >> v[i] >> w[i] >> k[i];
k[i]=min(k[i], s/w[i]);
vals[w[i]].push_back({v[i], k[i]});
}
for (int i=1; i<=s; i++)
{
if (vals[i].size()==0)
{
continue;
}
sort(vals[i].begin(), vals[i].end(), greater<pair<ll, ll>>());
ll am=s/i;
for (int j=0; j<vals[i].size(); j++)
{
while (am>0 && vals[i][j].second>0)
{
am--;
vals[i][j].second--;
dodp(vals[i][j].first, i);
}
if (am==0)
{
break;
}
}
}
for (int i=1; i<=s; i++)
{
ans=max(ans, dp[i]);
}
cout << ans << "\n";
}
| # | 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... |