Submission #1308276

#TimeUsernameProblemLanguageResultExecution timeMemory
1308276tolgaKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms1616 KiB
#include <iostream> #include <vector> typedef long long ll; #define endl '\n' ll dp[10005]; 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]; 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--) dp[j] = std::max(dp[j], dp[j - weight] + price); } } ll ans = 0; for (int i = 0; i <= s; i++) ans = std::max(ans, dp[i]); 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...