Submission #768948

#TimeUsernameProblemLanguageResultExecution timeMemory
768948xgon6576Knapsack (NOI18_knapsack)C++14
49 / 100
143 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int s, n; cin >> s >> n; vector<int> v; vector<int> w; v.push_back(0); w.push_back(0); for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; for (int j = 0; j < min(c, (s/b)+1); j++) { v.push_back(a); w.push_back(b); } } vector<vector<int>> dp(v.size()+1, vector<int>(s+1, 0)); for (int i = 1; i <= v.size(); i++) { for (int j = 0; j <= s; j++) { dp[i][j] = dp[i-1][j]; if (w[i] <= j) dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]); } } cout << dp[v.size()][s] << endl; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int i = 1; i <= v.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...