Language: C++


#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair  <int,int> ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set   <int>     si;
typedef set   <ii>      sii;
typedef vi::iterator itt;
typedef si::iterator jtt;

#define fori(i,x) for(itt i=x.begin();i!=x.end();i++)
#define forj(j,x) for(jtt j=x.begin();j!=x.end();j++)
#define all(x)   x.begin(), x.end()
#define clr(x,v) memset(x,v,sizeof(x))

#define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define endl "\n"
#define MOD int(1e9+7)
#define N 2123
ll n, a, b,  ma, mb, ans, v[N];
int moveu[N];
pair<ll,ii> move;
int main(){_
    cin >> n;
    a=0, b = n-1;
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    for(int i=0;i<n;i++){
        move.x=-1;
        for(int j=0;j<n;j++){
            if(moveu[j])continue;
            ma = abs(j-a)*v[j];
            mb = abs(j-b)*v[j];
            if(ma>mb){
                if(ma>move.x||(ma==move.x && v[j]<v[move.y.x])){
                    move = mp(ma,mp(j,0));
                }
            }
            else{
                if(mb>move.x||(mb==move.x && v[j]<v[move.y.x])){
                    move = mp(mb,mp(j,1));
                }
            }
        }
        
        ans+=move.x;
        int id = move.y.x, dir = move.y.y;
        moveu[id] = 1;
        //cout<<a<<' '<<b<<endl;
        //cout<<id<<' '<<dir<<' '<<move.x<<endl;
        if(dir==0){
            a++;
        }
        else{
            b--;
        }
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:9: error: reference to 'move' is ambiguous
   36 |         move.x=-1;
      |         ^~~~
In file included from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
In file included from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:61,
                 from /usr/include/c++/14/bits/stl_algobase.h:64:
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:28:13: note:                 'std::pair<long long int, std::pair<int, int> > move'
   28 | pair<ll,ii> move;
      |             ^~~~
a.cc:42:23: error: reference to 'move' is ambiguous
   42 |                 if(ma>move.x||(ma==move.x && v[j]<v[move.y.x])){
      |                       ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:28:13: note:                 'std::pair<long long int, std::pair<int, int> > move'
   28 | pair<ll,ii> move;
      |             ^~~~
a.cc:42:36: error: reference to 'move' is ambiguous
   42 |                 if(ma>move.x||(ma==move.x && v[j]<v[move.y.x])){
      |                                    ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:28:13: note:                 'std::pair<long long int, std::pair<int, int> > move'
   28 | pair<ll,ii> move;
      |             ^~~~
a.cc:42:53: error: reference to 'move' is ambiguous
   42 |                 if(ma>move.x||(ma==move.x && v[j]<v[move.y.x])){
      |                                                     ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:28:13: note:                 'std::pair<long long int, std::pair<int, int> > move'
   28 | pair<ll,ii> move;
      |             ^~~~
a.cc:43:21: error: reference to 'move' is ambiguous
   43 |                     move = mp(ma,mp(j,0));
      |                     ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:28:13: note:                 'std::pair<long long int, std::pair<int, int> > move'
   28 | pair<ll,ii> move;
      |             ^~~~
a.cc:47:23: error: reference to 'move' is ambiguous
   47 |                 if(mb>move.x||(mb==move.x && v[j]<v[move.y.x])){
      |                       ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:28:13: note:                 'std::pair<long long int, std::pair<int, int> > move'
   28 | pair<ll,ii> move;
      |             ^~~~
a.cc:47:36: error: reference to 'move' is ambiguous
   47 |                 if(mb>move.x||(mb==move.x && v[j]<v[move.y.x])){
      |                                    ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:28:13: note:                 'std::pair<long long int, std::pair<int, int> > move'
   28 | pair<ll,ii> move;
      |             ^~~~
a.cc:47:53: error: reference to 'move' is ambiguous
   47 |                 if(mb>move.x||(mb==move.x && v[j]<v[move.y.x])){
      |                                                     ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:28:13: note:                 'std::pair<long long int, std::pair<int, int> > move'
   28 | pair<ll,ii> move;
      |             ^~~~
a.cc:48:21: error: reference to 'move' is ambiguous
   48 |                     move = mp(mb,mp(j,1));
      |                     ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _