Submission #877719

#TimeUsernameProblemLanguageResultExecution timeMemory
877719Beerus13Knapsack (NOI18_knapsack)C++14
37 / 100
1072 ms464 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]; int ans = 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]; } memset(dp, -0x3f, sizeof(dp)); dp[0] = 0; for(int i = 1; i <= n; ++i) { for(int j = sl[i]; j >= 1; --j) { for(int k = S; k >= w[i]; --k) { dp[k] = max(dp[k], dp[k - w[i]] + val[i]); } } } for(int i = 1; i <= S; ++i) ans = max(ans, dp[i]); cout << ans; 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...