Submission #1370588

#TimeUsernameProblemLanguageResultExecution timeMemory
1370588luka2881Knapsack (NOI18_knapsack)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int s,n;
    cin>>s>>n;
    vector<int>v(n);
    vector<int>w(n);
    vector<int>k(n);
    vector<long long>dp(s+1,0);
    for(int i=0;i<n;i++)cin>>v[i]>>w[i]>>k[i];
    vector<vector<pair<int,int>>>p(s+1);
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    vector<pair<int,int>>a;
    for(int i=0;i<n;i++)
    {
        p[w[i]].push_back(make_pair(v[i],k[i]));
    }
    for(int i=1;i<=s;i++)
    {
        int uk=0;
        int j=0;
        while(j<p[i].size())
        {
            int k=0;
            while(k<p[i][j].second)
            {
                a.push_back(make_pair(p[i][j].first,i));
                k++;
                uk++;
                if(uk>s/i)break;
            }
            if(uk>s/i)break;
            j++;
        }
    }
    for(int i=0;i<a.size();i++)
    {
        vector<int>dppom(s+1);
        for(int j=a[i].second;j<=s;j++)
        {
            dppom[j]=max(dp[j],dp[j-a[i].second]+a[i].first);
        }
        dp=dppom;
    }
    cout<<dp[s]<<endl;
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:47:12: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and 'std::vector<int>')
   47 |         dp=dppom;
      |            ^~~~~
In file included from /usr/include/c++/13/vector:72,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from knapsack.cpp:1:
/usr/include/c++/13/bits/vector.tcc:210:5: note: candidate: 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::vector<long long int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/13/vector:66:
/usr/include/c++/13/bits/stl_vector.h:766:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<long long int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:788:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<long long int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~