제출 #877724

#제출 시각아이디문제언어결과실행 시간메모리
877724Beerus13Knapsack (NOI18_knapsack)C++14
73 / 100
1060 ms2908 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 5; int n, S, val[N], w[N], sl[N]; int dp[2005]; void sub1234() { memset(dp, -0x3f, sizeof(dp)); dp[0] = 0; for(int i = 1; i <= n; ++i) { for(int j = min(sl[i], S / w[i]); j >= 1; --j) { for(int k = S; k >= w[i]; --k) { dp[k] = max(dp[k], dp[k - w[i]] + val[i]); } } } int ans = 0; for(int i = 1; i <= S; ++i) ans = max(ans, dp[i]); cout << ans; exit(0); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> S >> n; for(int i = 1; i <= n; ++i) { cin >> val[i] >> w[i] >> sl[i]; } sub1234(); 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...