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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
#define pii pair<int,int>
signed main(){
long long n,s,x,v,k;
cin>>s>>n;
vector<int> dp(s+1);
vector<vector<pii>> elements(s+1,vector<pii>());
for(int i=0;i<n;i++){
cin>>v>>x>>k;
elements[x].push_back({v,k});
}
for(int i=1;i<=s;i++)sort(elements[i].begin(),elements[i].end());
for(int i=1;i<=s;i++){
int cnt=i;
while(cnt<=s&&elements[i].size()){
elements[i].back().second--;
for(int j=s;j>=i;j--){
dp[j]=max(dp[j],dp[j-i]+elements[i].back().first);
}
cnt+=i;
//cout<<cnt<<' ';
if(!elements[i].back().second)elements[i].pop_back();
}
}
long long ans=0;
for(int i=0;i<=s;i++){
ans=max(ans,dp[i]);
}
cout<<ans;
}
# | 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... |