Submission #463603

#TimeUsernameProblemLanguageResultExecution timeMemory
463603Duy_eKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
/*THINK GONNA FAIL ? IF U DIDNT FAIL THEN WHAT IS THE POINT OF LEARNING */ #include <bits/stdc++.h> #define ll long long #define pii pair<long long, long long> #define ull unsigned long long #define st first #define nd second #define lower_case_alphabet "abcdefghijklmnopqrstuvwxyz" #define upper_case_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define file "test" using namespace std; const long long oo = 1e18; const long long N = 1e5 + 5; ll s, n, cnt, dp[N], A[N]; vector <pii> d[2004]; void decompose(int x){ if (x == 0){ cnt = -1; return; } cnt = 0; ll sum = 1; while (x > sum){ x -= sum; A[cnt++] = sum; sum <<= 1; } A[cnt] = x; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for (int i = 1, v, w, k; i <= n; i ++){ cin >> v >> w >> k; k = min(k, s); d[w].push_back({v, k}); } for (int i = 0; i <= s; i ++) if (d[i].size()) for (pii p: d[i]){ decompose(p.nd); for (ll W, V; cnt >= 0; cnt --){ W = A[cnt]*i, V = A[cnt]*p.st; for (int j = s; j >= W; j --) dp[j] = max(dp[j], dp[j-W] + V); } } cout << dp[s]; return 0; } // sketch out every idea before see any solution, it helps alots. /** /\_/\ * (= ._.) * / >0 \>1 **/

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:42:21: error: no matching function for call to 'min(int&, long long int&)'
   42 |         k = min(k, s);
      |                     ^
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:2:
/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:42:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   42 |         k = min(k, s);
      |                     ^
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:2:
/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:42:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   42 |         k = min(k, s);
      |                     ^
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:2:
/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:42:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   42 |         k = min(k, s);
      |                     ^
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:2:
/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:42:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   42 |         k = min(k, s);
      |                     ^