Submission #693401

#TimeUsernameProblemLanguageResultExecution timeMemory
693401vjudge1Knapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int W, n; cin >> W >> n; vector<array<int, 2>> a; // { (value, weight) } vector<vector<array<long long, 2>>> mp(W + 1); for (int i = 0; i < n; i++) { int v, w, cnt; cin >> v >> w >> cnt; mp[w].push_back({v, cnt}); } for (int w = 1; w <= W; w++) { sort(mp[w].begin(), mp[w].end(), greater<>()); int needed = W / w; for (auto [v, cnt] : mp[w]) { for (int i = 0; i < min(needed, cnt); i++) { a.push_back({v, w}); } needed -= cnt; } } n = a.size(); vector<long long> dp(W + 1, 0); for (int i = 1; i <= n; i++) { for (int w = W; w >= a[i - 1][1]; w--) { dp[w] = max( dp[w], dp[w - a[i - 1][1]] + a[i - 1][0] ); } } long long ans = 0; for (int w = 0; w <= W; w++) { ans = max(ans, dp[w]); } cout << ans << "\n"; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:23:48: error: no matching function for call to 'min(int&, std::tuple_element<1, std::array<long long int, 2> >::type&)'
   23 |             for (int i = 0; i < min(needed, cnt); i++) {
      |                                                ^
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:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
knapsack.cpp:23:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::tuple_element<1, std::array<long long int, 2> >::type' {aka 'long long int'})
   23 |             for (int i = 0; i < min(needed, cnt); i++) {
      |                                                ^
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:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
knapsack.cpp:23:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::tuple_element<1, std::array<long long int, 2> >::type' {aka 'long long int'})
   23 |             for (int i = 0; i < min(needed, cnt); i++) {
      |                                                ^
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:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
knapsack.cpp:23:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   23 |             for (int i = 0; i < min(needed, cnt); i++) {
      |                                                ^
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:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
knapsack.cpp:23:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   23 |             for (int i = 0; i < min(needed, cnt); i++) {
      |                                                ^
knapsack.cpp:24:30: warning: narrowing conversion of 'v' from 'std::tuple_element<0, std::array<long long int, 2> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   24 |                 a.push_back({v, w});
      |                              ^