Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

const ll INF = 1000000000000000000;

int n, a, b, p[5010], x[5010];
int cum[5010][5010];
ll d[5010][5010];
ll ans = INF;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++)cin >> p[i], x[p[i]] = i;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
		if (i < p[j])cum[i][j] = cum[i][j - 1] + 1;
		else cum[i][j] = cum[i][j - 1];
	}
	for (int i = 1; i <= n; i++)for (int j = 1; j <= i; j++)d[i][j] = INF;
	d[1][1] = 0;
	for (int i = 1; i < n; i++){
		for (int j = 1; j <= i; j++) {
			ll k = d[i][j];
			if (x[i + 1] < x[j])k += a;
			if (x[j] + 1 < x[i + 1])k += min((ll)b, (ll)a*(cum[i + 1][x[i + 1]] - cum[i + 1][x[j]]));
			d[i + 1][j] = min(d[i + 1][j], k);
		}
		int cnt = 0;
		for (int j = 1; j <= i; j++) {
			if (x[j] < x[i + 1])d[i + 1][i + 1] = min(d[i + 1][i + 1], d[i][j] + min(b, (ll)a*(cum[i + 1][x[i + 1]] - cum[i + 1][x[j]])));
			if (x[j] < x[i + 1])cnt++;
		}
		d[i + 1][i + 1] = min(d[i + 1][i + 1], (ll)cnt*a + (ll)(i - cnt)*b);
	}
	for (int i = 1; i <= n; i++)ans = min(ans, d[n][i]);
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:81:97: error: no matching function for call to 'min(int&, ll)'
   81 |                         if (x[j] < x[i + 1])d[i + 1][i + 1] = min(d[i + 1][i + 1], d[i][j] + min(b, (ll)a*(cum[i + 1][x[i + 1]] - cum[i + 1][x[j]])));
      |                                                                                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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: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++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:81:97: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   81 |                         if (x[j] < x[i + 1])d[i + 1][i + 1] = min(d[i + 1][i + 1], d[i][j] + min(b, (ll)a*(cum[i + 1][x[i + 1]] - cum[i + 1][x[j]])));
      |                                                                                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/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++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:81:97: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   81 |                         if (x[j] < x[i + 1])d[i + 1][i + 1] = min(d[i + 1][i + 1], d[i][j] + min(b, (ll)a*(cum[i + 1][x[i + 1]] - cum[i + 1][x[j]])));
      |                                                                                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~