Submission #1277919

#TimeUsernameProblemLanguageResultExecution timeMemory
1277919shirokitoKnapsack (NOI18_knapsack)C++20
73 / 100
1097 ms16968 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> void maximize(T &a, T b) { if (a < b) a = b; } const int N = 1e5 + 24; int n, s; vector<pair<ll, ll>> a; ll dp[N]; void solve() { cin >> s >> n; for (int i = 1; i <= n; i++) { ll v, w, k; cin >> v >> w >> k; ll p = 1; while (k) { if (k >= p) { a.push_back({w * p, v * p}); k -= p; p *= 2; } else { a.push_back({w * k, v * k}); k = 0; } } } for (auto [w, v]: a) { for (int i = s; i >= w; i--) { maximize(dp[i], dp[i - w] + v); } } cout << dp[s] << '\n'; } int main() { cin.tie(0) -> sync_with_stdio(0); int 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...