# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
729246 | PVSekhar | Knapsack (NOI18_knapsack) | C++14 | Compilation error | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
// #endif
ll n,s;
cin>>s>>n;
vector<ll> dp(s+1,0);
dp[0]=1;
map<ll,vector<pair<ll,ll>>> store;
ll v,w,k;
for (ll i = 0; i < n; i++)
{
cin>>v>>w>>k;
store[w].push_back({v,k});
}
for (auto st:store)
{
sort(st.second.begin(),st.second.end(),greater<int>());
}
ll ind=0,x=0;
for (ll i = 1; i <= s; i++)
{
ind=0;
if(store[i].size()==0)continue;
for (ll j = 0; j <= (s/i); j++)
{
if(store[i][ind].second){
store[i][ind].second--;
x=store[i][ind].first;
}else{
ind++;
if(ind<(ll)store[i].size()){
store[i][ind].second--;
x=store[i][ind].first;
}
}
if(ind>=(ll)store[i].size())break;
for (ll k = s; k >= 0; k--)
{
if(dp[k]&&i+k<=s)dp[i+k]=max(dp[i+k],dp[k]+x);
}
}
}
ll ans=0;
for (ll i = 0; i <= s; i++)
{
ans=max(ans,dp[i]);
}
cout<<ans-1<<endl;
return 0;
}
Compilation message (stderr)
In file included from /usr/include/c++/10/bits/stl_algobase.h:71, 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:1: /usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = std::greater<int>]': /usr/include/c++/10/bits/stl_algo.h:82:17: required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1924:34: required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1958:38: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1974:25: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:4892:18: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = std::greater<int>]' knapsack.cpp:26:62: required from here /usr/include/c++/10/bits/predefined_ops.h:156:30: error: no match for call to '(std::greater<int>) (std::pair<long long int, long long int>&, std::pair<long long int, long long int>&)' 156 | { return bool(_M_comp(*__it1, *__it2)); } | ~~~~~~~^~~~~~~~~~~~~~~~ In file included from /usr/include/c++/10/string:48, from /usr/include/c++/10/bits/locale_classes.h:40, from /usr/include/c++/10/bits/ios_base.h:41, from /usr/include/c++/10/ios:42, 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:1: /usr/include/c++/10/bits/stl_function.h:375:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = int]' 375 | operator()(const _Tp& __x, const _Tp& __y) const | ^~~~~~~~ /usr/include/c++/10/bits/stl_function.h:375:29: note: no known conversion for argument 1 from 'std::pair<long long int, long long int>' to 'const int&' 375 | operator()(const _Tp& __x, const _Tp& __y) const | ~~~~~~~~~~~^~~ In file included from /usr/include/c++/10/bits/stl_algobase.h:71, 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:1: /usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = std::pair<long long int, long long int>; _Iterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = std::greater<int>]': /usr/include/c++/10/bits/stl_algo.h:1826:20: required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1854:36: required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1886:25: required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1977:31: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:4892:18: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = std::greater<int>]' knapsack.cpp:26:62: required from here /usr/include/c++/10/bits/predefined_ops.h:238:23: error: no match for call to '(std::greater<int>) (std::pair<long long int, long long int>&, std::pair<long long int, long long int>&)' 238 | { return bool(_M_comp(__val, *__it)); } | ~~~~~~~^~~~~~~~~~~~~~ In file included from /usr/include/c++/10/string:48, from /usr/include/c++/10/bits/locale_classes.h:40, from /usr/include/c++/10/bits/ios_base.h:41, from /usr/include/c++/10/ios:42, 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:1: /usr/include/c++/10/bits/stl_function.h:375:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = int]' 375 | operator()(const _Tp& __x, const _Tp& __y) const | ^~~~~~~~ /usr/include/c++/10/bits/stl_function.h:375:29: note: no known conversion for argument 1 from 'std::pair<long long int, long long int>' to 'const int&' 375 | operator()(const _Tp& __x, const _Tp& __y) const | ~~~~~~~~~~~^~~ In file included from /usr/include/c++/10/bits/stl_algobase.h:71, 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:1: /usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Value = std::pair<long long int, long long int>; _Compare = std::greater<int>]': /usr/include/c++/10/bits/stl_heap.h:139:48: required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Distance = long int; _Tp = std::pair<long long int, long long int>; _Compare = __gnu_cxx::__ops::_Iter_comp_val<std::greater<int> >]' /usr/include/c++/10/bits/stl_heap.h:246:23: required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Distance = long int; _Tp = std::pair<long long int, long long int>; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_heap.h:355:22: required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1666:23: required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1937:25: required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1953:27: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:1974:25: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]' /usr/include/c++/10/bits/stl_algo.h:4892:18: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >; _Compare = std::greater<int>]' knapsack.cpp:26:62: required from here /usr/include/c++/10/bits/predefined_ops.h:194:23: error: no match for call to '(std::greater<int>) (std::pair<long long int, long long int>&, std::pair<long long int, long long int>&)' 194 | { return bool(_M_comp(*__it, __val)); } | ~~~~~~~^~~~~~~~~~~~~~ In file included from /usr/include/c++/10/string:48, from /usr/include/c++/10/bits/locale_classes.h:40, from /usr/include/c++/10/bits/ios_base.h:41, from /usr/include/c++/10/ios:42, 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:1: /usr/include/c++/10/bits/stl_function.h:375:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = int]' 375 | operator()(const _Tp& __x, const _Tp& __y) const | ^~~~~~~~ /usr/include/c++/10/bits/stl_function.h:375:29: note: no known conversion for argument 1 from 'std::pair<long long int, long long int>' to 'const int&' 375 | operator()(const _Tp& __x, const _Tp& __y) const | ~~~~~~~~~~~^~~