제출 #847815

#제출 시각아이디문제언어결과실행 시간메모리
847815dubabubaKnapsack (NOI18_knapsack)C++14
73 / 100
1061 ms2724 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int mxn = 1e5 + 10; const int mxs = 2000 + 9; int n, s, ans; int pr[mxn], we[mxn], am[mxn]; vector<int> a(mxs, 0), b(mxs, 0); signed main() { cin.tie(0)->sync_with_stdio(0); cin >> s >> n; for(int i = 1; i <= n; i++) cin >> pr[i] >> we[i] >> am[i]; for(int i = 1; i <= n; i++) { for(int j = 0; j <= s; j++) { for(int k = 0; k <= am[i] && k * we[i] <= j; k++) b[j] = max(b[j], a[j - k * we[i]] + k * pr[i]); ans = max(ans, b[j]); } swap(a, b); } cout << ans << '\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...