This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<long long, long long>
#define pb push_back
#define st first
#define nd second
using namespace std;
const int N = 100005;
const int inf = 1000000000;
ll maxx (ll a, ll b)
{
if (a>b)
return a;
return b;
}
int n,s,v[N],g[N] ,k[N],dp[N];
int main()
{
cin >> s >> n;
for (int i=1;i<=n;i++)
cin >> v[i] >> g[i] >> k[i],k[i]=min(k[i],s/g[i]+1);
fill(dp+1,dp+s+2,-1);
dp[0]=0;
for (int i=1;i<=n;i++)
for (int j=1;k[i]>0;j++)
{
ll t=min(k[i],j);
k[i]-=j;
ll f=t*g[i];
for (int l=s;l>=f;l--)
if (dp[l-f]>-1)
dp[l]=maxx(dp[l],dp[l-f]+v[i]*t);
}
for (int i=1;i<=s;i++)
{
dp[i]=maxx(dp[i],dp[i-1]);
}
cout << dp[s];
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... |