Submission #1276540

#TimeUsernameProblemLanguageResultExecution timeMemory
1276540almazKnapsack (NOI18_knapsack)C++20
73 / 100
1096 ms16904 KiB
#include <bits/stdc++.h> using namespace std; #define int long long // #define endl '\n' #define ff first #define ss second #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ar array const int MOD = 1e9 + 7,INF = 1e18, N = 2e5 + 5; /* */ void solve(){ int s , n; cin >> s >> n; vector <pair<int,int>> a; for(int i = 0;i < n;i++){ int v , w , k; cin >> v >> w >> k; int h = 1; while(k > 0){ int x = min(k , h); a.pb({v * x , w * x}); k -= x; h *= 2; } } vector <int> dp(2001, 0); dp[0] = 0; for(int i = 0;i < (int)a.size();i++){ for(int j = 2000;j >= a[i].ss;j--){ dp[j] = max(dp[j] , dp[j - a[i].ss] + a[i].ff); } } // for(int i = 0;i <= s;i++){ // cout<<dp[i]<<' '; // } // cout<<endl; int ans = 0; for(int i = 0;i <= s;i++){ ans = max(ans , dp[i]); } cout<<ans<<endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int ti = 1; // cin >> ti; while (ti--) { solve(); } }
#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...