Submission #482674

#TimeUsernameProblemLanguageResultExecution timeMemory
482674OlympiaKnapsack (NOI18_knapsack)C++17
12 / 100
2 ms972 KiB
#include <cmath> #include <iostream> #include <set> #include <climits> #include <algorithm> #include <cassert> #include <vector> #include <iomanip> #include <type_traits> #include <string> #include <queue> #include <map> using namespace std; #define ll long long struct item { int weight; int worth; }; int main() { int S, N; cin >> S >> N; vector<item> items; for (int i = 0; i < N; i++) { int wei, wor; cin >> wor >> wei; int cnt; cin >> cnt; for (int j = 0; j < min(cnt, S/wei); j++) { items.push_back({wei, wor}); } } int dp[items.size() + 1][S + 1]; //taking i items, what is the best worth that we can get for (int i = 0; i < items.size() + 1; i++) { for (int j = 0; j <= S; j++) { dp[i][j] = 0; } } for (int i = 1; i <= items.size(); i++) { for (int j = 0; j <= S; j++) { if (j - items[i - 1].weight >= 0) { dp[i][j] = max(dp[i - 1][j - items[i - 1].weight] + items[i - 1].worth, dp[i - 1][j]); } } } cout << dp[items.size()][S] << endl; }

Compilation message (stderr)

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