제출 #1101066

#제출 시각아이디문제언어결과실행 시간메모리
1101066votranngocvyKnapsack (NOI18_knapsack)C++14
100 / 100
42 ms35144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define fi first #define se second const int N = 2e3 + 5; vector<pii>vec[N]; ll dp[N][N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int s,n; cin >> s >> n; for (int i = 1; i <= n; i++) { int v,w,k; cin >> v >> w >> k; vec[w].push_back({v,k}); } for (int i = 1; i <= 2000; i++) sort(vec[i].begin(),vec[i].end(),greater<pii>()); ll ans = 0; for (int i = 1; i <= 2000; i++) for (int j = 1; j <= s; j++) { dp[i][j] = dp[i - 1][j]; ll sumW = 0,sumV = 0; for (auto x: vec[i]) { int num = x.se,v = x.fi; for (int z = 1; z <= num; z++) { sumV += v,sumW += i; if (sumW > j) break; dp[i][j] = max(dp[i][j],dp[i - 1][j - sumW] + sumV); } if (sumW > j) break; } ans = max(ans,dp[i][j]); } cout << ans << "\n"; }
#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...