This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//https://oj.uz/problem/view/NOI18_knapsack
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)
typedef long long ll;
const int MAXN = 2005;
int dp[MAXN][MAXN];
struct item{
int v,cnt;
friend bool operator < (item a, item b){
return a.v>b.v;
}
};
int main(){
FASTIO;
int m,n;
cin>>m>>n;
vector<vector<item>> a(m+1);
for(int i=1;i<=n;i++){
int v,w,t;
cin>>v>>w>>t;
a[w].push_back({v,t});
}
int i=1;
for(int w=1;w<=m;w++,i++){
sort(a[w].begin(),a[w].end());
int cw=0,cv=0;
for(int j=1;j<=m;j++)
dp[i][j]=dp[i-1][j];
for(auto obj:a[w]){
if(cw>m)
break;
for(int k=1;k<=obj.cnt;k++){
cw+=w;
cv+=obj.v;
if(cw>m)
break;
for(int j=cw;j<=m;j++)
dp[i][j] = max(dp[i][j], dp[i-1][j-cw]+cv);
}
}
}
int ans=0;
for(int j=1;j<=m;j++)
ans=max(ans,dp[i][j]);
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... |