Submission #676843

#TimeUsernameProblemLanguageResultExecution timeMemory
676843ToxtaqKnapsack (NOI18_knapsack)C++17
37 / 100
1100 ms25128 KiB
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int S, N, sz = 0;
    cin >> S >> N;
    vector<int>values, weights;
    for(int i = 0;i < N;++i){
        int V, W, K;
        cin >> V >> W >> K;
        for(int j = 0;j < K;++j){
            values.push_back(V);
            weights.push_back(W);
        }
        sz += K;
    }
    vector<long long>dp(S + 1, -1e9);
    long long mx = 0;
    dp[0] = 0;

    for(int j = 0;j < sz;++j){
        for(int i = S;i >= 0;--i){
            if(i - weights[j] >= 0)dp[i] = max(dp[i - weights[j]] + 1LL * values[j], dp[i]);
//            cout << j << ", " << i << ": " << dp[i] << '\n';
            mx = max(mx, dp[i]);
        }
    }
    cout << mx;
}
#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...