Submission #674651

#TimeUsernameProblemLanguageResultExecution timeMemory
674651ZuraKnapsack (NOI18_knapsack)C++14
73 / 100
1080 ms3884 KiB
#include <bits/stdc++.h>
#define int long long int
#define mod 1000000007
using namespace std;
signed main()
{
    // ios_base::sync_with_stdio(NULL);
    // cin.tie(NULL);
    // freopen("feast.in", "r", stdin);
    // freopen("feast.out", "w", stdout);
    int s, n;
    cin >> s >> n;
    int v[n], w[n], k[n];
    for (int i = 0; i < n; i++)
    {
        cin >> v[i] >> w[i] >> k[i];
    }
    vector<int> dp(s + 1);
    for (int i = 0; i < n; i++)
    {
        for (int j = s; j >= w[i]; j--)
        {
            for (int l = 1; l <= min(k[i], (j / w[i])); l++)
            {
                dp[j] = max(dp[j], l * v[i] + dp[j - l * w[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...