Submission #763205

#TimeUsernameProblemLanguageResultExecution timeMemory
763205AlvamauKnapsack (NOI18_knapsack)C++14
0 / 100
4 ms9940 KiB
//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 val,cnt; friend bool operator < (item x,item y){ return x.val > y.val;} }; int32_t main(){ FASTIO; int m,n; cin >> m >> n; vector < vector < item > > vt(m+1); for (int i=1;i<=n;i++){ int v,w,t; cin >> v >> w >> t; vt[w].push_back({v,t}); } int i=1; for (int w=1;w<=m;w++,i++){ sort(vt[w].begin(),vt[w].end()); int cw=0,cv=0; for (int j=1;j<=m;j++) dp[i][j]=dp[i-1][j]; for (auto f:vt[w]){ if (cw>m) break; for (int k=1;k<=f.cnt;k++){ cw+=w; cv+=f.val; 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; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...