Submission #1113118

#TimeUsernameProblemLanguageResultExecution timeMemory
1113118buzdiKnapsack (NOI18_knapsack)C++17
73 / 100
1045 ms2908 KiB
#include <iostream> #include <map> #include <vector> #include <queue> #include <cassert> #define ll long long using namespace std; const int NMAX = 1e5; const ll INF = 1e18; const int SMAX = 2000; int S, n; int v[NMAX + 1], w[NMAX + 1], k[NMAX + 1]; ll dp[SMAX + 1], answer; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> S >> n; for(int i = 1; i <= n; i++) { cin >> v[i] >> w[i] >> k[i]; } for (int i = 0; i <= S; i++) { dp[i] = -INF; } dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = S; j >= w[i]; j--) { for (int c = 1; c <= k[i] && j - w[i] * c >= 0; c++) { if (dp[j - w[i] * c] != -INF) { dp[j] = max(dp[j], dp[j - w[i] * c] + (ll) v[i] * c); } } } } answer = -INF; for (int j = 0; j <= S; j++) { answer = max(answer, dp[j]); } cout << answer << '\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...