Submission #679657

#TimeUsernameProblemLanguageResultExecution timeMemory
679657nicolexxuuKnapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int main() { int S, N; cin >> S >> N; map<int, vector<pair<int, int>>> by_weight; for(int t = 0; t < N; t++) { int V, W, K; cin >> V >> W >> K; by_weight[W].push_back({V, K}); } vector<vector<long long>> dp(by_weight.size()+1, vector<long long>(S+1)); int res = 0; int i = 1; for(auto& hi : by_weight) { auto w = hi.first; auto items = hi.second; for(int s = 1; s <= S; s++) { dp[i][s] = dp[i-1][s]; int curr_i = 0, curr_cnt = 0, val = 0; for(int cnt = 1; cnt * w <= s && curr_i < items.size(); cnt++) { val += items[curr_i].first; if(++curr_cnt == items[curr_i].second) { curr_cnt = 0; curr_i++; } dp[i][s] = max(dp[i][s], dp[i-1][s-cnt*w] + val); } } res = max(dp[i][S], res); i++; } cout << res << endl; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:27:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |    for(int cnt = 1; cnt * w <= s && curr_i < items.size(); cnt++) {
      |                                     ~~~~~~~^~~~~~~~~~~~~~
knapsack.cpp:37:26: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int&)'
   37 |   res = max(dp[i][S], res);
      |                          ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
knapsack.cpp:37:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   37 |   res = max(dp[i][S], res);
      |                          ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
knapsack.cpp:37:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   37 |   res = max(dp[i][S], res);
      |                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
knapsack.cpp:37:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   37 |   res = max(dp[i][S], res);
      |                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
knapsack.cpp:37:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   37 |   res = max(dp[i][S], res);
      |                          ^