Submission #1308273

#TimeUsernameProblemLanguageResultExecution timeMemory
1308273tolgaKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms1608 KiB
#include <iostream> #include <vector> typedef long long ll; #define endl '\n' int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int s, n; std::cin >> s >> n; std::vector<int> p(n), w(n), cnt(n); for (int i = 0; i < n; i++) std::cin >> p[i] >> w[i] >> cnt[i]; std::vector<ll> dp(s + 1); ll ans = 0; for (int i = 0; i < n; i++) { int K = cnt[i], get = 1; while (K) { int br = std::min(get, K); K -= br, get <<= 1; ll weight = 1LL * br * w[i], price = 1LL * br * p[i]; for (int j = s; j >= weight; j--) if (dp[j] < dp[j - weight] + price) { dp[j] = dp[j - weight] + price; ans = std::max(ans, dp[j]); } } } std::cout << ans << 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...