Submission #1041360

#TimeUsernameProblemLanguageResultExecution timeMemory
1041360daviolimenKnapsack (NOI18_knapsack)C++17
73 / 100
1094 ms19036 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int S, N, dp[2001], peso[3000000], val[3000000];

int32_t main() {
    cin >> S >> N;
    int ctr = 0;
    for (int i = 0; i < N; i++) {
        int c = 1, v, w, k; cin >> v >> w >> k;
        while (c < k) {
            k -= c;
            peso[++ctr] = w * c;
            val[ctr] = v * c;
            c *= 2;
        }
        peso[++ctr] = w * k;
        val[ctr] = v * k;
    }

    for (int i = 1; i <= ctr; i++) {
        for (int j = S; j >= peso[i]; j--) {
            dp[j] = max(dp[j], dp[j - peso[i]] + val[i]);
        }
    }

    cout << dp[S] << "\n";
}
#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...