Compile Error

/in/foo.cc: In function 'int main()':
/in/foo.cc:20:34: error: no matching function for call to 'max(short int&, int)'
   20 |                         dp[j]=max(dp[j],dp[j-a[i].p]+a[i].v);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/12/string:50,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/istream:38,
                 from /usr/include/c++/12/sstream:38,
                 from /usr/include/c++/12/complex:45,
                 from /usr/include/c++/12/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:54,
                 from /in/foo.cc:1:
/usr/include/c++/12/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/12/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
/in/foo.cc:20:34: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   20 |                         dp[j]=max(dp[j],dp[j-a[i].p]+a[i].v);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/12/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
/in/foo.cc:20:34: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   20 |                         dp[j]=max(dp[j],dp[j-a[i].p]+a[i].v);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/12/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:65:
/usr/include/c++/12/bits/stl_algo.h:5746:5: note: candidate: 'template<class _Tp> _Tp std::max(initializer_list<_Tp>)'
 5746 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/12/bits/stl_algo.h:5746:5: note:   template argument deduction/substitution failed:
/in/foo.cc:20:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   20 |                         dp[j]=max(dp[j],dp[j-a[i].p]+a[i].v);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12/bits/stl_algo.h:5756:5: note: candidate: 'template<class _Tp, class _Compare> _Tp std::max(initializer_list<_Tp>, _Compare)'
 5756 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/12/bits/stl_algo.h:5756:5: note:   template argument deduction/substitution failed:
/in/foo.cc:20:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   20 |                         dp[j]=max(dp[j],dp[j-a[i].p]+a[i].v);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

信息

递交者
类型
自测
题目
P3018 道具商店202512GESP6级T2
语言
C++
递交时间
2026-02-24 09:47:38
评测时间
2026-02-24 09:47:38
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes