Language: C++

#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i,0,n-1){
        int b;
        cin >> b;
        a[i] = make_pair(b,i);
    }
    ll mt[n][n];
    priority_queue<tuple<ll,int,int>> pq;
    rep(i,0,n-1){
        rep(j,0,n-1){
            ll k = a[i].first;
            int idx = a[i].second;
            mt[i][j] = k * abs(idx - j);
            pq.push(make_tuple(mt[i][j],i,j));
        }
    }
    ll ans = 0;
    set<int> si,sj;
    while(!pq.empty()){
        auto now = pq.top();pq.pop();
        auto itri = si.find(get<2>(now));
        auto itrj = sj.find(get<3>(now));
        if(itri != si.end())continue;
        if(itrj != sj.end())continue;
        ans += get<1>(now);
        si.insert(get<2>(now));
        sj.insert(get<3>(now));


    }
    // matprint(mt,n,n);

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/tuple: In instantiation of 'struct std::tuple_element<3, std::tuple<long long int, int, int> >':
/usr/include/c++/14/bits/utility.h:84:11:   required by substitution of 'template<long unsigned int __i, class _Tp> using std::__tuple_element_t = typename std::tuple_element::type [with long unsigned int __i = 3; _Tp = std::tuple<long long int, int, int>]'
   84 |     using __tuple_element_t = typename tuple_element<__i, _Tp>::type;
      |           ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/tuple:2466:5:   required by substitution of 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(const tuple<_Elements ...>&&) [with long unsigned int __i = 3; _Elements = {long long int, int, int}]'
 2466 |     get(const tuple<_Elements...>&& __t) noexcept
      |     ^~~
a.cc:42:35:   required from here
   42 |         auto itrj = sj.find(get<3>(now));
      |                             ~~~~~~^~~~~
/usr/include/c++/14/tuple:2422:25: error: static assertion failed: tuple index must be in range
 2422 |       static_assert(__i < sizeof...(_Types), "tuple index must be in range");
      |                     ~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/tuple:2422:25: note: the comparison reduces to '(3 < 3)'
In file included from /usr/include/c++/14/bits/stl_pair.h:62,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/utility.h: In instantiation of 'struct std::_Nth_type<3, long long int, int, int>':
/usr/include/c++/14/tuple:2424:13:   required from 'struct std::tuple_element<3, std::tuple<long long int, int, int> >'
 2424 |       using type = typename _Nth_type<__i, _Types...>::type;
      |             ^~~~
/usr/include/c++/14/bits/utility.h:84:11:   required by substitution of 'template<long unsigned int __i, class _Tp> using std::__tuple_element_t = typename std::tuple_element::type [with long unsigned int __i = 3; _Tp = std::tuple<long long int, int, int>]'
   84 |     using __tuple_element_t = typename tuple_element<__i, _Tp>::type;
      |           ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/tuple:2466:5:   required by substitution of 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(const tuple<_Elements ...>&&) [with long unsigned int __i = 3; _Elements = {long long int, int, int}]'
 2466 |     get(const tuple<_Elements...>&& __t) noexcept
      |     ^~~
a.cc:42:35:   required from here
   42 |         auto itrj = sj.find(get<3>(now));
      |                             ~~~~~~^~~~~
/usr/include/c++/14/bits/utility.h:237:13: error: '__type_pack_element' index is out of range
  237 |     { using type = __type_pack_element<_Np, _Types...>; };
      |             ^~~~
a.cc: In function 'int main()':
a.cc:42:35: error: use of deleted function 'constexpr std::__enable_if_t<(__i >= sizeof... (_Types))> std::get(const tuple<_Elements ...>&) [with long unsigned int __i = 3; _Elements = {long long int, int, int}; __enable_if_t<(__i >= sizeof... (_Types))> = void]'
   42 |         auto itrj = sj.find(get<3>(now));
      |                             ~~~~~~^~~~~
/usr/include/c++/14/tuple:2476:5: note: declared here
 2476 |     get(const tuple<_Elements...>&) = delete;
      |     ^~~
a.cc:42:35: note: use '-fdiagnostics-all-candidates' to display considered candidates
   42 |         auto itrj = sj.find(get<3>(now));
      |                             ~~~~~~^~~~~
a.cc:47:25: error: use of deleted function 'constexpr std::__enable_if_t<(__i >= sizeof... (_Types))> std::get(const tuple<_Elements ...>&) [with long unsigned int __i = 3; _Elements = {long long int, int, int}; __enable_if_t<(__i >= sizeof... (_Types))> = void]'
   47 |         sj.insert(get<3>(now));
      |                   ~~~~~~^~~~~
/usr/include/c++/14/tuple:2476:5: note: declared here
 2476 |     get(const tuple<_Elements...>&) = delete;
      |     ^~~
a.cc:47:25: note: use '-fdiagnostics-all-candidates' to display considered candidates
   47 |         sj.insert(get<3>(now));
      |                   ~~~~~~^~~~~