Submission #502036

#TimeUsernameProblemLanguageResultExecution timeMemory
502036pawnedKnapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; ll dp[100000][2050]; struct itemtype { ll weight, cost, number; }; bool cmp(const itemtype& x, const itemtype& y) { if (x.weight != y.weight) return x.weight < y.weight; if (x.cost != y.cost) return x.cost > y.cost; if (x.number != y.number) return x.number < y.number; return true; } int main() { ll S, N; // maxweight, itemcount cin>>S>>N; itemtype types[N]; // weight, cost, number for (int i = 0; i < N; i++) { cin>>types[i].cost>>types[i].weight>>types[i].number; } sort(types, types + N, cmp); vector<pair<ll, ll>> items; // {weight, cost} items.pb({-1, -1}); ll currweight = 1; ll currneeded = S / currweight; for (int i = 0; i < N; i++) { if (types[i].weight != currweight || currneeded <= 0) { currweight = types[i].weight; currneeded = S / currweight; } ll toadd = max(min(types[i].number, currneeded), 0); for (int j = 0; j < toadd; j++) { items.pb({types[i].weight, types[i].cost}); } currneeded -= toadd; } /* for (int i = 0; i < items.size(); i++) { cout<<"item "<<i<<": "<<items[i].first<<", "<<items[i].second<<endl; } */ ll maximum = 0; for (int i = 1; i < (int)(items.size()); i++) { for (int j = 0; j <= S; j++) { dp[i][j] = dp[i - 1][j]; if (j >= items[i].first) dp[i][j] = max(dp[i][j], dp[i - 1][j - items[i].first] + items[i].second); // cout<<i<<" "<<j<<": "<<dp[i][j]<<endl; maximum = max(maximum, dp[i][j]); } } cout<<maximum<<endl; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:44:53: error: no matching function for call to 'max(const long long int&, int)'
   44 |   ll toadd = max(min(types[i].number, currneeded), 0);
      |                                                     ^
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: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:44:53: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   44 |   ll toadd = max(min(types[i].number, currneeded), 0);
      |                                                     ^
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: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:44:53: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   44 |   ll toadd = max(min(types[i].number, currneeded), 0);
      |                                                     ^
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:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
knapsack.cpp:44:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   44 |   ll toadd = max(min(types[i].number, currneeded), 0);
      |                                                     ^
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:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
knapsack.cpp:44:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   44 |   ll toadd = max(min(types[i].number, currneeded), 0);
      |                                                     ^