Submission #813097

#TimeUsernameProblemLanguageResultExecution timeMemory
813097AliVuKnapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define el '\n' const int maxn = 2e3 + 3, N = 1e5 + 5; int dp[2][maxn]; vector<pair<int, int>> a; void Solve() { int S, n; cin >> S >> n; for(int i = 1; i <= n; i++) { int v, w, k; cin >> v >> w >> k; k = min(k, 2000); int p = 1; while(p < k) { a.push_back({v * p, w * p}); k -= p; p <<= 1; } if(k) a.push_back({v * k, w * k}); } for(int i = 0; i < 2; i++) for(int j = 0; j < maxn; j++) { dp[i][j] = -1; if(j == 0) dp[i][j] = 0; } for(int k = 0; k < a.size(); k++) { int i = k % 2; for(int j = 0; j < maxn; j++) { if(dp[i][j] != -1 && j + a[k].second < maxn) dp[1 - i][j + a[k].second] = max(dp[1 - i][j + a[k].second], dp[i][j] + a[k].first); dp[1 - i][j] = max(dp[1 - i][j], dp[i][j]); } } int ans = 0; for(int i = 1; i <= S; i++) { ans = max({ans, dp[0][i], dp[1][i]}); } cout << ans; } signed main() { ios_base::sync_with_stdio(false);cin.tie(0); int t = 1;// cin >> t; while(t--) Solve(); }

Compilation message (stderr)

knapsack.cpp: In function 'void Solve()':
knapsack.cpp:13:23: error: no matching function for call to 'min(long long int&, int)'
   13 |        k = min(k, 2000);
      |                       ^
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:13:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   13 |        k = min(k, 2000);
      |                       ^
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:13:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   13 |        k = min(k, 2000);
      |                       ^
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:13:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   13 |        k = min(k, 2000);
      |                       ^
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:13:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   13 |        k = min(k, 2000);
      |                       ^
knapsack.cpp:27:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int k = 0; k < a.size(); k++) {
      |                    ~~^~~~~~~~~~