Submission #1053951

#TimeUsernameProblemLanguageResultExecution timeMemory
1053951ssitaramKnapsack (NOI18_knapsack)C++17
12 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct item { ll v, w, k; }; int main() { ios::sync_with_stdio(0); cin.tie(nullptr); ll s, n; cin >> s >> n; vector<item> v(n); for (ll i = 0; i < n; ++i) { cin >> v[i].v >> v[i].w >> v[i].k; } vector<ll> best(s + 1); for (ll i = 0; i < n; ++i) { ll fr = 0; for (ll j = 0; j <= s; ++j) { if (best[j] > best[fr] + v[i].v * min((j - fr) / v[i].w, v[i].k)) { fr = j; } best[j] = max(best[j], best[fr] + v[i].v * min((j - fr) / v[i].w, v[i].k)); } } cout << *max_element(best.begin(), best.end()) << '\n'; 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...