Submission #1345866

#TimeUsernameProblemLanguageResultExecution timeMemory
1345866hojiakbar2011Knapsack (NOI18_knapsack)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ll long long
#define int long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define mp make_pair

void setIO(string s = "") {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    if (!s.empty()) {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
}

void solve() {
    
}

signed main() {
    setIO(); // or setIO("file")
    ll s, n;
    cin>>s>>n;
    vector<vector<ll>> v(s+1);
    while(n--){
        ll val, w, k;
        cin>>val>>w>>k;
        k=min(k, s/w);
        for(int num=1;num<=k;num++){
            v[w].pb({val});
        }
    }
    vector<ll> dp(s+1, 0);
    for(int w=1;w<=s;w++){
        sort(v[w].rbegin(), v[w].rend());
        for(int k=0;k<min(s/w, v[w].size()*1LL);k++){
            for(int i=s;i>=w;i--){
                dp[i]=max(dp[i], dp[i-w]+v[w][k]);
            }
        }
    }
    cout<<dp[s];
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:43:26: error: no matching function for call to 'min(long long int, long long unsigned int)'
   43 |         for(int k=0;k<min(s/w, v[w].size()*1LL);k++){
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
knapsack.cpp:43:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   43 |         for(int k=0;k<min(s/w, v[w].size()*1LL);k++){
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note:   template argument deduction/substitution failed:
knapsack.cpp:43:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   43 |         for(int k=0;k<min(s/w, v[w].size()*1LL);k++){
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5775:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5775 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5775:5: note:   template argument deduction/substitution failed:
knapsack.cpp:43:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   43 |         for(int k=0;k<min(s/w, v[w].size()*1LL);k++){
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5785:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5785 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5785:5: note:   template argument deduction/substitution failed:
knapsack.cpp:43:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   43 |         for(int k=0;k<min(s/w, v[w].size()*1LL);k++){
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp: In function 'void setIO(std::string)':
knapsack.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~