Submission #942485

#TimeUsernameProblemLanguageResultExecution timeMemory
942485AtabayRajabliKnapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

// author : a1abay

#define all(v)      v.begin(), v.end()
#define GCD(a, b)   __gcd(a, b)
#define int ll 
#define LCM(a, b)   (a*b / (__gcd(a, b)))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long           ll;
const int inf =             1e9 + 7;
const int inff =            (int)1e18 + 7;
const int sz =              1e5 + 5;
using namespace             std;

int s, n;
int v[sz], w[sz], f[sz], dp[sz];
vector<array<int, 2>> g[sz];

signed main()   
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // freopen("in.in", "r", stdin); freopen("out.out", "w", stdout);
    
    cin >> s >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i] >> w[i] >> f[i];
        g[w[i]].push_back({v[i], f[i]});
    }
    for(int i = 1; i <= s; i++)
    {
        sort(all(g[i]));
        
        int mx = s / i;
        while(!g[i].empty())
        {
            int x = g[i].back()[1], v = g[i].back()[0];
            if(mx - x < 0)break;
            g[i].pop_back();
            
            for(int j = 1; j <= x; j++)
            {
                for(int k = s; k >= i; k--)dp[k] = max(dp[k - i] + v, dp[k]);
            }
        }
        for(int j = 1; j <= mx; j++)
        {
            for(int k = s; k >= i; k--)dp[k] = max(dp[k - i] + v, dp[k]);
        }
    }
    int mx = -1;
    for(int i = 0; i <= m; i++)mx = max(mx, dp[i]);
    
    cout << mx;
}









Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:53:72: error: no matching function for call to 'max(ll*, ll&)'
   53 |             for(int k = s; k >= i; k--)dp[k] = max(dp[k - i] + v, dp[k]);
      |                                                                        ^
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:53:72: note:   deduced conflicting types for parameter 'const _Tp' ('long long int*' and 'll' {aka 'long long int'})
   53 |             for(int k = s; k >= i; k--)dp[k] = max(dp[k - i] + v, dp[k]);
      |                                                                        ^
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:53:72: note:   deduced conflicting types for parameter 'const _Tp' ('long long int*' and 'll' {aka 'long long int'})
   53 |             for(int k = s; k >= i; k--)dp[k] = max(dp[k - i] + v, dp[k]);
      |                                                                        ^
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:53:72: note:   mismatched types 'std::initializer_list<_Tp>' and 'll*' {aka 'long long int*'}
   53 |             for(int k = s; k >= i; k--)dp[k] = max(dp[k - i] + v, dp[k]);
      |                                                                        ^
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:53:72: note:   mismatched types 'std::initializer_list<_Tp>' and 'll*' {aka 'long long int*'}
   53 |             for(int k = s; k >= i; k--)dp[k] = max(dp[k - i] + v, dp[k]);
      |                                                                        ^
knapsack.cpp:57:25: error: 'm' was not declared in this scope
   57 |     for(int i = 0; i <= m; i++)mx = max(mx, dp[i]);
      |                         ^