Submission #1357181

#TimeUsernameProblemLanguageResultExecution timeMemory
1357181vjudge1Knapsack (NOI18_knapsack)C++20
37 / 100
1095 ms1860 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    int S, N; cin >> S >> N;
    vector<tuple<ll, ll, ll>> items(N+1);

    for (int i = 1; i <= N; i++) {
        ll v,w,k; cin >> v >> w >> k;
        items[i] = make_tuple(v,w,k);
    }

    vector<vector<ll>> dp(N+1, vector<ll>(S+1, 0));

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= get<2>(items[i]); j++) {
            for (int z = 0; z <= S; z++) {
                ll newWeight = z + get<1>(items[i]) * j;
                if (newWeight <= S) {
                    dp[i][newWeight] = max(dp[i][newWeight], dp[i-1][z] + get<0>(items[i]) * j);
                }
            }
        }
    }

    ll ans{0};
    for (int i = 0; i <= S; i++) {
        ans = max(ans, dp[N][i]);
    }

    cout << ans << endl;




    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...