Submission #491325

#TimeUsernameProblemLanguageResultExecution timeMemory
491325DDTerziev04Knapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
#include<iostream> using namespace std; const int MAXN=1e5, MAXS=2000; long long dp[MAXS+1]; long long p[MAXN], w[MAXN], h[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long s, n; cin >> s >> n; for(int i=0; i<n; i++) { cin >> p[i] >> w[i] >> h[i]; } for(int i=0; i<=s; i++) { dp[i]=-1; } dp[0]=0; int ans=0; for(int i=0; i<n; i++) { for(int j=s; j>=0; j--) { for(int u=1; u<=h[i] && u*w[i]<=j; u++) { if(dp[j-u*w[i]]==-1) { continue; } dp[j]=max(dp[j], dp[j-u*w[i]]+u*p[i]); } ans=max(ans, dp[j]); } } cout << ans << "\n"; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:43:31: error: no matching function for call to 'max(int&, long long int&)'
   43 |             ans=max(ans, dp[j]);
      |                               ^
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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 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:43:31: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   43 |             ans=max(ans, dp[j]);
      |                               ^
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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 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:43:31: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   43 |             ans=max(ans, dp[j]);
      |                               ^