제출 #756362

#제출 시각아이디문제언어결과실행 시간메모리
756362asdasdqwerKnapsack (NOI18_knapsack)C++17
73 / 100
262 ms262144 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; int main() { int s, n; cin >> s >> n; vector<int64_t> dp(s+1, 0); vector<pair<int64_t, int64_t>> items; if (n == 1) { int64_t v, w, k; cin >> v >> w >> k; int times = min(s / w, k); cout << v * times << "\n"; return 0; } for (int i = 0; i < n; i++) { int64_t v, w, k; cin >> v >> w >> k; k = min((s / w) + 1, k); for (int j = 0; j < k; j++) { items.push_back(make_pair(w, v)); } } int size = items.size(); for (int i = 0; i < size; i++) { for (int j = s; j > 0; j--) { if ((j - items[i].first > -1)) { dp[j] = max(dp[j - items[i].first] + items[i].second, dp[j]); } } } cout << dp[s] << "\n"; }
#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...