Submission #794322

#TimeUsernameProblemLanguageResultExecution timeMemory
794322theghostkingKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int dp[2005][2005]; int search(int i, int remW, vector<pair<int,int>>& kp, int total){ if (i == total) return 0; if (remW == 0) return 0; if (dp[i][remW] != -1) return dp[i][remW]; if (kp[i].first <= remW){ return dp[i][remW] = max(search(i+1,remW,kp,total),search(i+1,remW-kp[i].first,kp,total)+kp[i].second); } else{ return dp[i][remW] = search(i+1,remW,kp,total); } } signed main() { memset(dp,-1,sizeof(dp)); int s,n; cin >> s >> n; vector<int> arr[2000];//offset weight by one for now for (int i = 0; i<n; i++){ int v,w,k; cin >> v >> w >> k; k = min(2000,k); w--; int sz1 = arr[w].size(); int left = min(2000-sz1,k); for (int j = 0; j<left; j++){ arr[w].push_back(v); } } int total = 0; vector<pair<int,int>> kp; for (int i = 0; i<2000; i++){ int sz = arr[i].size(); total += sz; for (int j = 0; j<sz; j++){ kp.push_back({i+1,arr[i][j]}); //weight,value } } cout << search(0,s,kp,total) << '\n'; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:28:23: error: no matching function for call to 'min(int, long long int&)'
   28 |         k = min(2000,k);
      |                       ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 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:28:23: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   28 |         k = min(2000,k);
      |                       ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 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:28:23: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   28 |         k = min(2000,k);
      |                       ^
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:28:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   28 |         k = min(2000,k);
      |                       ^
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:28:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   28 |         k = min(2000,k);
      |                       ^