제출 #674636

#제출 시각아이디문제언어결과실행 시간메모리
674636ZuraKnapsack (NOI18_knapsack)C++14
12 / 100
1 ms296 KiB
#include <bits/stdc++.h> #define int long long int #define mod 1000000007 using namespace std; signed main() { // ios_base::sync_with_stdio(NULL); // cin.tie(NULL); // freopen("feast.in", "r", stdin); // freopen("feast.out", "w", stdout); int s, n; cin >> s >> n; int v[n], w[n], k[n]; for (int i = 0; i < n; i++) { cin >> v[i] >> w[i] >> k[i]; } vector<pair<int, int>> dp(s + 1, {0, 0}); for (int i = 0; i < n; i++) { for (int j = 0; j <= s; j++) dp[j].second = 0; for (int j = w[i]; j <= s; j++) { if (dp[j - w[i]].second < k[i] && (v[i] + dp[j - w[i]].first) > dp[j].first) dp[j] = {v[i] + dp[j - w[i]].first, dp[j - w[i]].second + 1}; } } cout << (*max_element(dp.begin(), dp.end())).first << "\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...