Submission #1274342

#TimeUsernameProblemLanguageResultExecution timeMemory
1274342kiteyuKnapsack (NOI18_knapsack)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5;
const int M=2e6;
int s,n,n1=0;
struct node{
    int v;
    int w;
    int k;
}a[N+5],b[M+5];
int dp[2005];

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>s>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i].v>>a[i].w>>a[i].k;
        a[i].k=min(a[i].k,s/a[i].w);
        int fs = 0;
        for(int j=10;j>=0;--j) if(((a[i].k >> j)&1)){
            fs=j;
            break;
        }
        for(int j=0;j<fs;++j){
            b[++n1]={a[i].v,a[i].w,(1<<j)};
            a[i].k-=(1<<j);
        }
        if(a[i].k)
        b[++n1]=a[i];
    }
//
//    for(int i=1;i<=n1;++i)
//        cout<<b[i].v<<' '<<b[i].w<<' '<<b[i].k<<'\n';

    for(int i=1;i<=n1;++i){
        int W=b[i].w*b[i].k;
        int val=b[i].k*b[i].v;
//        cout<<W<<' '<<val<<'\n';
        for(int j=s-W;j>=0;--j){
//            cout<<j<<','<<dp[i]+val<<'\n';
            dp[j+W]=max(dp[j+W],dp[j]+val);
        }
//        for(int j=0;j<=s;++j) cout<<dp[j]<<' ';
//        cout<<'\n';

    }
    ll ans=0;
    for(int i=0;i<=s;++i)
        ans=max(ans,dp[i]);
    cout<<ans;
    return 0;
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:50:16: error: no matching function for call to 'max(ll&, int&)'
   50 |         ans=max(ans,dp[i]);
      |             ~~~^~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from knapsack.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
knapsack.cpp:50:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   50 |         ans=max(ans,dp[i]);
      |             ~~~^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
knapsack.cpp:50:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   50 |         ans=max(ans,dp[i]);
      |             ~~~^~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
knapsack.cpp:50:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   50 |         ans=max(ans,dp[i]);
      |             ~~~^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
knapsack.cpp:50:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   50 |         ans=max(ans,dp[i]);
      |             ~~~^~~~~~~~~~~