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;
typedef long long int ll;
ll dp[2222];
int main()
{
int s,n;
cin>>s>>n;
vector<pair<ll,ll>>items;
for(int i=0;i<n;i++){
ll v,w,k;
cin>>v>>w>>k;
for(int i=0;;i++){
ll p = (1LL<<i);
if(k>=p){
k-=p;
items.push_back({v*p,w*p});
}
else break;
}
if(k)items.push_back({v*k,w*k});
}
for(auto x : items){
ll v = x.first;
ll w = x.second;
for(int i = s;i >= w;i--)dp[i] = max(dp[i],dp[i - w] + v);
}
ll ans = 0;
for(int i=0;i<=s;i++)ans = max(ans,dp[i]);
cout<<ans<<'\n';
}
# | 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... |