제출 #1020157

#제출 시각아이디문제언어결과실행 시간메모리
1020157ArthuroWichKnapsack (NOI18_knapsack)C++17
37 / 100
1008 ms452 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int void solve() { int s, n; cin >> s >> n; vector<int> dp(s+1, -1); dp[0] = 0; for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; for (int x = 1; x <= k; x++) { for (int j = s; j >= 0; j--) { if (j-w >= 0 && dp[j-w] != -1) { dp[j] = max(dp[j], dp[j-w]+v); } } } } int ans = 0; for (int i : dp) { ans = max(ans, i); } cout << ans << endl; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t; t = 1; while(t--) { solve(); } }
#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...