Submission #1295562

#TimeUsernameProblemLanguageResultExecution timeMemory
1295562michaeltaranikKnapsack (NOI18_knapsack)C++17
0 / 100
172 ms327680 KiB
#include <iostream> #include <limits.h> #include <vector> #include <array> using namespace std; typedef long long ll; #define SIZE 1e9 void solve() { int s, n; cin >> s >> n; array<ll, (LLONG_MAX/1000)> dp; for (int i = 0; i < n; ++i) { int w; ll v, q; cin >> v >> w >> q; // fucking binary optimization for (ll k = 1; q > 0; k <<= 1) { ll take = min(k, q); ll chunkV = take * v; ll chunkW = take * w; if (chunkW <= s) { for (int j = s; j >= chunkW; --j) { dp[j] = max(dp[j], dp[j - chunkW] + chunkV); } } q -= take; } } cout << dp[s] << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); 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...