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 fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
using namespace std;
void solve()
{
int s,n;
cin >> s >> n;
long long dp[s+1]={0};
vector<long long> v,w;
for(int i=1;i<=n;i++)
{
int a,b,c;
cin >> a >> b >> c;
int p=1;
while(c>=p)
{
c-=p;
v.push_back(1ll*a*p);
w.push_back(1ll*b*p);
p<<=1;
if(1ll*b*p>s) break;
}
if(c&&1ll*b*c<=s)
{
v.push_back(1ll*a*c);
w.push_back(1ll*b*c);
}
}
for(int i=0;i<(int)w.size();i++) for(int j=s;j>=w[i];j--) dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
cout << dp[s] << endl;
}
int main()
{
fastIO
solve();
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... |