Submission #563929

#TimeUsernameProblemLanguageResultExecution timeMemory
563929NeriWKnapsack (NOI18_knapsack)C++17
12 / 100
3 ms3412 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, int> pill;
typedef vector<pill> vpill;
typedef vector<vpill> vvpill;
int main()
{
    //freopen("..\\io\\input.txt", "r", stdin);
    //freopen("..\\io\\output.txt", "w", stdout);
    int s, n; cin >> s >> n;
    vll k(n+1, 0);
    vll v(n+1, 0);
    vll w(n+1, 0);
    vvpill dp(n+1, vpill(s+1, {0,0}));
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i] >> w[i] >> k[i];
    }
    for(int i = 1; i <= n; i++)
    {
        for(int m = 1; m <= w[i]; m++)
        {
            for(int j = m; j <= s; j+=w[i])
            {
                if(dp[i][j- w[i]].second < k[i] && j  - w[i] >= 0)
                {
                    if(dp[i][j].first < dp[i][j-w[i]].first + v[i])
                    {
                        dp[i][j] = {dp[i][j-w[i]].first + v[i], dp[i][j-w[i]].second + 1};
                    }
                }
                if(dp[i][j].first < dp[i-1][j].first)
                {
                    dp[i][j] = dp[i-1][j];
                    dp[i][j].second = 0;
                }
                if(dp[i][j].first < dp[i][j-1].first)
                        dp[i][j] = max(dp[i][j], dp[i][j-1]);
            }
               
        }
    }
    /*for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= s; j++)
        {
            cout << dp[i][j].first << ", " << dp[i][j].second << " ";
        }
        cout << "\n";
    }*/
    cout << dp[n][s].first;

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