Submission #944528

#TimeUsernameProblemLanguageResultExecution timeMemory
944528raul2008487Knapsack (NOI18_knapsack)C++17
100 / 100
92 ms7412 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define eb emplace_back #define vl vector<ll> #define fi first #define se second #define in insert #define mpr make_pair #define lg(x) __lg(x) #define bpc(x) __builtin_popcount(x) #define all(v) v.begin(), v.end() #define endl "\n" using namespace std; const int sz = 1e5+5; const ll inf = 100000000000000000; vl v(sz), w(sz), k(sz), dp(sz); vector<array<ll, 2>> A[2005]; void solve(){ ll S, n, i, j; cin >> S >> n; for(i = 1; i <= n; i++){ cin >> v[i] >> w[i] >> k[i]; A[w[i]].pb({v[i], k[i]}); } for(i = 1;i <= S; i++){ if(A[i].empty()){continue;} sort(all(A[i])); ll hi = S / i; while(hi-- && (!A[i].empty())){ for(j = S; j >= i; j--){ if(dp[j - i] + A[i].back()[0] > dp[j]){ dp[j] = dp[j - i] + A[i].back()[0]; } } A[i].back()[1]--; if(A[i].back()[1] == 0){A[i].pop_back();} } } ll ans = 0; for(i = 1; i <= S; i++){ ans = max(ans, dp[i]); } cout << ans << endl; } int main() { ll t = 1; ///cin >> t; while(t--){ 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...