Submission #877920

#TimeUsernameProblemLanguageResultExecution timeMemory
877920codexistentKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <queue> using namespace std; #define FOR(i, a, b) for(int i = a; i <= b; i++) #define FOR_EXC(i, a, b) for(int i = a; i < b; i++) int main(){ int S, N; long long V, W, K; cin >> S >> N; long long DP[N + 1][S + 1]; // DP[items 1...n][shopping cart size used] FOR(n, 0, N) FOR(s, 0, S) DP[n][s] = 0ll; FOR(n, 1, N){ cin >> V >> W >> K; K = max(K, N); deque<pair<long long, int>> sw; // sliding window deck FOR(a, 0, W - 1){ for(int s = a, i = 0; s <= S; s += W, i++){ DP[n][s] = DP[n - 1][s]; if(!sw.empty()) DP[n][s] = max(DP[n][s], sw.front().first + V*i); // update deck if(!sw.empty() && i - sw.front().second >= K) { sw.pop_front(); } long long upd = DP[n - 1][s] - V*i; while(!sw.empty() && sw.back().first < upd) sw.pop_back(); sw.push_back(make_pair(upd, i)); } } sw.clear(); } long long R = 0; FOR(s, 0, S) R = max(R, DP[N][s]); cout << R << endl; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:16:20: error: no matching function for call to 'max(long long int&, int&)'
   16 |        K = max(K, N);
      |                    ^
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:16:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   16 |        K = max(K, N);
      |                    ^
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:16:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   16 |        K = max(K, N);
      |                    ^