#include <bits/stdc++.h>
using namespace std;
int S, N;
vector<pair<int, int>> items;
void solve()
{
cin >> S >> N;
int price, award, cnt;
vector<int> dp(S + 1, 0);
for(int i = 0 ; i < N ; ++i)
{
cin >> award >> price >> cnt;
int p = 1;
while(p <= cnt)
{
cnt -= p;
for(int j = S ; j >= price * p ; --j)
{
dp[j] = max(dp[j], dp[j - price * p] + award * p);
}
p *= 2;
}
if(cnt)
{
for(int j = S ; j >= price * cnt ; --j)
{
dp[j] = max(dp[j], dp[j - price * cnt] + award * cnt);
}
}
}
cout << dp[S] << "\n";
}
void fastIO()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main()
{
fastIO();
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... |