#include<bits/stdc++.h>
#define Daniel_1997 void
using namespace std;
//\\ PRINCIPAL \\//
#define oo 1e18
#define endl "\n"
#define int long long
#define mod 800000007
#define tle while(1){;}
#define ios ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0)
//\\ BITS \\//
#define bits_1 __builtin_popcount
//\\ STL \\//
#define pb push_back
#define fr first
#define sc second
#define lb lower_bound
#define all(x) x.begin(), x.end()
//\\ FAST OPERATIONS \\//
#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define sfl(n) scanf("%I64d", &n)
#define sffl(n,m) scanf("%I64d%I64d",&n,&m)
#define pf(n) printf("%d\n",n)
#define pfl(n) printf("%I64d ",n)
int32_t main() {
int s,n;
cin >> s >> n;
vector< pair< int, pair< int,int> > >v(n);
for(int i = 0; i < v.size(); i++)
{
cin >> v[i].fr >> v[i].sc.fr >> v[i].sc.sc;
if(v[i].sc.sc > s)v[i].sc.sc = s;
}
vector< pair< int, pair< int,int> > >v2;
for(auto i : v)
{
int aux = i.sc.sc;
for(int j = 0; j < 32; j++)
{
int aux2 = (1LL << j);
if(aux >= aux2)
{
v2.pb({i.fr * (1 << j),{i.sc.fr * (1 << j),1}});
aux -= aux2;
}
}
if(aux == 0)continue;
v2.pb({i.fr * aux,{i.sc.fr * aux,1}});
}
vector<int>dp(s + 1,0);
for(auto i : v2)
{
for(int j = s; j >= i.sc.fr; j--)
{
dp[j] = max(dp[j],dp[j - i.sc.fr] + i.fr);
}
}
int maxx = 0;
for(int i : dp)
{
maxx = max(maxx,i);
}
cout << maxx << 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... |