Submission #1309228

#TimeUsernameProblemLanguageResultExecution timeMemory
1309228hyyhKnapsack (NOI18_knapsack)C++20
100 / 100
93 ms2088 KiB
#include <iostream> #include <math.h> #include <vector> #include <string> #include <algorithm> #include <queue> #include <stack> #include <map> #include <cstring> #include <iomanip> #include <set> #include <bitset> using namespace std; using ll = long long; using pii = pair<int,int>; using piii = tuple<int,int,int>; #define endl '\n' #define f first #define s second int const N = 2010; vector<piii> vc; int cnt[N]; vector<pii> all; int dp[N]; int main(){ int n,m;cin >> n >> m; for(int i = 0;i < m;i++){ int w,v,k;cin >> v >> w >> k; vc.emplace_back(v,w,k); } sort(vc.begin(),vc.end(),greater<piii>()); for(auto [val,weight,amount]:vc){ //cout << weight << " " << val << endl; int temp = amount; while(cnt[weight] <= (n/weight) && temp--){ all.emplace_back(weight,val); cnt[weight]++; } } for(auto k:all){ //cout << k.f << " " << k.s << endl; for(int i = n;i >= k.f;i--){ dp[i] = max(dp[i],dp[i-k.f]+k.s); } } cout << dp[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...