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;
#define int long long
int32_t main(){
int s, n;
cin>>s>>n;
vector<vector<pair<int, int>>> val(s+1, vector<pair<int, int>>(0));
vector<int> dp(s+1, -1e18);
for(int i=1;i<=n;++i){
int a, b, c;
cin>>a>>b>>c;
val[b].push_back({a, c});
}
for(int i=1;i<=s;++i) sort(val[i].rbegin(), val[i].rend());
dp[0]=0;
for(int i=1;i<=s;++i){
int x=0;
for(auto it:val[i]){
for(int j=1;j<=it.second;++j){
x+=i;
for(int k=s;k>=x;--k) dp[k]=max(dp[k], dp[k-i]+it.first);
if(x>s) break;
}
if(x>s) break;
}
}
int sol=0;
for(int i=0;i<=s;++i) sol=max(sol, dp[i]);
cout<<sol<<"\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... |