Submission #859986

#TimeUsernameProblemLanguageResultExecution timeMemory
859986GithubKnapsack (NOI18_knapsack)C++17
73 / 100
189 ms262144 KiB
#include <iostream> #include <vector> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll n, s; cin >> s >> n; vector<ll> value(n); vector<ll> weight(n); vector<ll> freq(n); for (int i = 0; i < n; i++){ cin >> value[i] >> weight[i] >> freq[i]; } ll dp[s+1][n+1]; for (int i = 0; i <= n; i++){ for (int w = 0; w <= s; w++){ if ((i == 0) || (w == 0)){ dp[w][i] = 0; }else { dp[w][i] = 0; for (int r = 0; r <= freq[i-1] && (r*weight[i-1] <= w); r++){ dp[w][i] = max(dp[w][i], dp[w-weight[i-1]*r][i-1] + r*value[i-1]); } } } } cout << dp[s][n] << endl; return 0; }
#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...