Submission #975423

#TimeUsernameProblemLanguageResultExecution timeMemory
975423vjudge1Knapsack (NOI18_knapsack)C++98
37 / 100
155 ms262144 KiB
#include <bits/stdc++.h>
using  namespace std;
int main(){
    int s,n;
    cin>>s>>n;
    vector<int>v,w;
    int banyak=0;
    int tv,tw,tk;
    v.push_back(0);
    w.push_back(0);
    for (int i = 1; i <= n; i++)
    {
       
       cin>>tv>>tw>>tk;
        banyak+=tk;
       while (tk--)
       {
        v.push_back(tv);
        w.push_back(tw);
       }
    }
    
    int dp[banyak+1][s+1];
    for (int i = 0; i <= s; i++)
    {
        dp[0][i]=0;
    }
    for (int i = 0; i <= banyak; i++)
    {
        dp[i][0]=0;
    }
    for (int i = 1; i <= banyak; i++)
    {
        for (int j = 1; j <= s; j++)
        {
            if(w[i]>j){
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            }
        }
    }
    cout<<dp[banyak][s];
    
}
#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...