Submission #1092555

#TimeUsernameProblemLanguageResultExecution timeMemory
1092555AryanPadarthiKnapsack (NOI18_knapsack)C++11
37 / 100
1064 ms348 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; int main() { int w; int n; int mval=0; cin >> w >> n; vector<long long> points(n); vector<int> weight(n); vector<int> count(n); for (int i = 0; i < n; i++){ cin >> points[i] >> weight[i] >> count[i]; } vector<long long> dp(w+1,0); //dp[0]=1; for (int i = 0; i < n; i++){ for (int j = 0; j < count[i]; j++){ for (int k = dp.size()-1; k > -1; k--){ if (dp[k] > 0){ if (k+weight[i]<dp.size()){ dp[k+weight[i]] = max(dp[k+weight[i]],dp[k]+points[i]); } } } if (j==0){ dp[weight[i]] = max(dp[weight[i]],points[i]); } } } for (int i = 0; i < dp.size(); i++){ if (dp[i]>mval){ mval = dp[i]; } } cout << mval; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |      if (k+weight[i]<dp.size()){
      |          ~~~~~~~~~~~^~~~~~~~~~
knapsack.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i = 0; i < dp.size(); 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...