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 dp[10005];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("TEST.inp","r",stdin);
//freopen("dpknste2.inp","r",stdin);
// freopen("dpknste2.out","w",stdout);
int n,m; cin>>m>>n;
map<int,vector<pair<int,int>>>mp;
for(int i=1;i<=n;i++)
{
int x,y,z; cin>>y>>x>>z;
mp[x].push_back({y,z});
}
for(auto it:mp)
{
sort(it.second.begin(),it.second.end(),greater<pair<int,int>>());
for(int j=m;j>=it.first;j--)
{
int cur_i=0,cnt=0,copy=0;
long long profit=0;
while((copy+1)*it.first<=j&&cur_i<it.second.size())
{
copy++;
cnt++;
profit+=1ll*it.second[cur_i].first;
dp[j]=max(dp[j],dp[j-copy*it.first]+profit);
if(cnt==it.second[cur_i].second)
{
cnt=0;
cur_i++;
}
}
}
}
cout<<dp[m];
return 0;
}
Compilation message (stderr)
knapsack.cpp: In function 'int main()':
knapsack.cpp:25:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | while((copy+1)*it.first<=j&&cur_i<it.second.size())
| ~~~~~^~~~~~~~~~~~~~~~~
# | 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... |