Submission #1273250

#TimeUsernameProblemLanguageResultExecution timeMemory
1273250arkanefuryKnapsack (NOI18_knapsack)C++17
12 / 100
9 ms10304 KiB
#include <bits/stdc++.h> #define pb push_back #define S second #define F first #define FOR(x, n, m, d) for(int x = n; x <= m; x += d) #define FORR(x, n, m, d) for(int x = n; x >= m; x -= d) #define nikita ios_base::sync_with_stdio(0), cin.tie(0); using namespace std; const int N = 2050; int n, cost, weight, number, m, ans; int dp[N], dp1[N][N], x, y; vector<pair<int, int>>g[N]; vector<int>v[N]; signed main(){ cin >> m >> n; FOR(i, 1, n,1 ){ cin >> cost >> weight >> number; if(weight <= m)g[weight].pb({cost, number}); } FOR(i, 1, m, 1)sort(g[i].begin(), g[i].end()); FOR(i, 1, m, 1){ for(auto j : g[i]){ while(j.S != 0 && v[i].size() < m/i)v[i].pb(j.F), j.S --; } } ans = 0; FOR(i, 1, m, 1){ dp[i] = -2e9; y=-1; FORR(j, i-1, 0, 1){ x = i-j; if(v[x].size() >= 1 + dp1[j][x] && dp[i] < dp[j] + v[x][ v[x].size() - 1 - dp1[j][x] ]){ dp[i] = dp[j] + v[x][ v[x].size() - 1 - dp1[j][x] ]; y = j; } } if(y==-1)continue; FOR(j, 1, m, 1)dp1[i][j] += dp1[y][j]; dp1[i][i-y] ++; ans = max(ans, dp[i]); } cout << ans; }
#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...