Submission #676846

#TimeUsernameProblemLanguageResultExecution timeMemory
676846ToxtaqKnapsack (NOI18_knapsack)C++17
49 / 100
375 ms262144 KiB
#include<bits/stdc++.h> using namespace std; int main() { int S, N, sz = 0; cin >> S >> N; vector<int>values, weights; int V, W, K; if(N == 1){ cin >> V >> W >> K; int num = S / W; cout << 1LL * min(num, K) * V; return 0; } for(int i = 0;i < N;++i){ cin >> V >> W >> K; for(int j = 0;j < K;++j){ values.push_back(V); weights.push_back(W); } sz += K; } vector<long long>dp(S + 1, -1e9); long long mx = 0; dp[0] = 0; for(int j = 0;j < sz;++j){ for(int i = S;i >= 0;--i){ if(i - weights[j] >= 0)dp[i] = max(dp[i - weights[j]] + 1LL * values[j], dp[i]); // cout << j << ", " << i << ": " << dp[i] << '\n'; mx = max(mx, dp[i]); } } cout << mx; }
#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...