제출 #1053953

#제출 시각아이디문제언어결과실행 시간메모리
1053953ssitaramKnapsack (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; } if (j != 0) best[j] = max(best[j], best[j - 1]); 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...