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
using namespace std;
using pll = pair<ll,ll>;
const int N=1e5+5, mod=998244353;
ll dp[N],c[N],w[N],v[N];
//dp[j] = max(dp[j], dp[j - z*w[i]] + z*v[i])
map<ll,vector<pll>> mp;
int main(){
int tar, n; cin >> tar >> n;
for(int i=0;i<n;i++){
ll w,v,k; cin>>v >> w >> k;
mp[w].push_back({v,k});
}
ll ans = 0;
memset(dp,0,sizeof(dp));
// w: {v1...vn}
for(auto&it:mp){
sort(begin(it.second),end(it.second),greater<>());
ll w = it.first;
for(auto& p:it.second){
ll v = p.first, copies=p.second;
for(int j=tar;j>=0;j--){
if(j < w) continue;
for(int z=0;z<=copies;z++){
if(j >= z*w)
dp[j] = max(dp[j], dp[j - z*w]+v*z);
else break;
}
ans = max(dp[j],ans);
}
}
}
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... |