Submission #1043685

#TimeUsernameProblemLanguageResultExecution timeMemory
1043685suyangbanKnapsack (NOI18_knapsack)C++14
37 / 100
1043 ms2396 KiB
#include <bits/stdc++.h>
using namespace std;

int s, n;
long long v[100001], w[100001], k[100001];
long long dp[100001];

int main(){
    scanf("%d%d", &s, &n);
    for(int i=1; i<=n; i++){
        scanf("%lld%lld%lld", &v[i], &w[i], &k[i]);
    }
    for(int i=1; i<=n; i++){
        for(int kk=0; kk<k[i]; kk++){
            for(int j=s; j>=w[i]; j--){
                dp[j]=max(dp[j], dp[j-w[i]]+v[i]);
            }
        }
    }

    printf("%lld", dp[s]);
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d%d", &s, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%lld%lld%lld", &v[i], &w[i], &k[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...