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>
using namespace std;
long long s,n;
vector<pair<long long,pair<long long,long long>>>x;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin>>s>>n;
long long dp[s+1];
long long D[s+1];
memset(D,0,sizeof D);
memset(dp,0,sizeof dp);
for(long long i=0;i<n;i++)
{
long long v,w,k;
cin>>v>>w>>k;
x.push_back({v,{w,k}});
}
for(long long i=0;i<n;i++)
{
for(int idx=0;idx<s+1;idx++)
{
D[idx]=dp[idx];
}
for(long long j=1;j<=min(s,x[i].second.second);j++)
{
if(s-j*x[i].second.first<=0)break;
for(long long p=s;p>=j*x[i].second.first;p--)
{
dp[p]=max(dp[p],D[p-j*x[i].second.first]+j*x[i].first);
}
}
}
cout<<dp[s]<<endl;
}
# | 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... |