제출 #876264

#제출 시각아이디문제언어결과실행 시간메모리
876264__Davit__Knapsack (NOI18_knapsack)C++17
73 / 100
1042 ms3032 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ff first #define ss second #define pb push_back #define vr(v) v.begin(),v.end() #define rv(v) v.rbegin(),v.rend() #define Code ios_base::sync_with_stdio(false); #define By cin.tie(NULL); #define Davit cout.tie(NULL); using namespace std; //#include "algo/debug.h" int main() { Code By Davit int S, n; cin >> S >> n; vector<int> V(n), W(n), K(n); vector<vector<pair<int, int>>> by_weight(S + 5); // map<int, vector<pair<int, int>>> by_weight; for (int i = 0; i < n; i++) { cin >> V[i] >> W[i] >> K[i]; K[i] = min(K[i], S / W[i]); by_weight[W[i]].pb({V[i], K[i]}); } vector<int> dp(S + 5, 0); for (int x = 0; x <= S; x++) { for (int y = 0; y < (int) by_weight[x].size(); y++) { for (int cnt = 0; cnt < by_weight[x][y].ss; cnt++) { for (int k = S; k >= 0; k--) { if (k - x >= 0)dp[k] = max(dp[k], dp[k - x] + by_weight[x][y].ff); } } } } int answer = 0; for (int k = S; k >= 0; k--) { answer = max(answer, dp[k]); } cout << answer << endl; }
#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...