Language: C++

#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const ll mod = 1e9+7;
int n;
ll dp[2020][2020];
struct A
{
    ll  num,avl;
} a[5005];
int cmp(A a,A b)
{
    return a.avl>b.avl;
}
int work(int l,int r,int now)
{
    if(l>r)
        return a[now].avl;
    if(dp[l][r]!=-1)
        return dp[l][r];
    int fist=work(l,r-1,now+1)+a[now].avl*abs(a[now].num-r);
    int second=work(l+1,r,now+1)+a[now].avl*abs(a[now].num-l);
    dp[l][r]=max(dp[l][r],max(fist,second));
    return dp[l][r];
}
int main()
{
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=n; i++)
    {
        cin>>a[i].avl;
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    cout<<work(1,n,1);
    return 0;
}


Compiler output:
a.cc: In function 'int work(int, int, int)':
a.cc:36:17: error: no matching function for call to 'max(long long int&, const int&)'
   36 |     dp[l][r]=max(dp[l][r],max(fist,second));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/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++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:36:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   36 |     dp[l][r]=max(dp[l][r],max(fist,second));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/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++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:36:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |     dp[l][r]=max(dp[l][r],max(fist,second));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~