Language: C++

/**
 *Code Author: codeknight13
 *Institution: IIT(ISM)
**/
 
#include <bits/stdc++.h>
using namespace std;

//remember-> largest 2d memory that can be allocated is dp[5100][5100];
#define ll long long int
#define v vector
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define str string
#define pq priority_queue
#define vi vector< ll >
#define vii vector< vi >
#define viii vector< vii >
#define pii pair< ll, ll >
#define vpii vector< pii >
#define len length()
#define pb push_back
#define mp make_pair3
#define ff first
#define ss second
#define nl cout <<  endl
#define all(ar) ar.begin(), ar.end()
#define ini(X,Y) ll X; X=Y
#define inx(X) ll X; cin >> X
#define inxy(X, Y) ll X, Y; cin >> X >> Y
#define iter(arr) for (ll i=0; i<arr.size(); i++)
#define ret return
#define cont continue
ll inf=1000000007;

ll min1(ll a, ll b, ll c)
{
	ret (min(a,min(b,c)));
}
ll k,c;

ll solve(vi &arr, vi &dp, ll n)
{
	if (n<=1)
	{
		ret 0;
	}
	if (dp[n]!=-1)
	{
		ret dp[n];
	}
	ll cost=1e18;
	for (int i=1; i<=k; i++)
	{
		if (n-i>=2)
		cost=min(abs(arr[n]-arr[n-i])*abs(arr[n]-arr[n-i])+solve(arr,dp,n-i)+c,cost);
	}
	dp[n]=cost;
	ret dp[n];
}

int main()
{
	fast;
	ll n;
	cin >> n;
	cin >> c;
	k=n-1;
	vi arr(n+2);
	arr[0]=	1e18;
	arr[1]=	1e18;
	for (ll i=2; i<n+2; i++)
	{
		cin >> arr[i];
	}
	vi dp(n+2,-1);
	dp[2]=0;
	cout << solve(arr,dp,n+1);
	ret 0;
}
/**
 *Code Author: codeknight13
 *Institution: IIT(ISM)
**/
 
#include <bits/stdc++.h>
using namespace std;

//remember-> largest 2d memory that can be allocated is dp[5100][5100];
#define ll long long int
#define v vector
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define str string
#define pq priority_queue
#define vi vector< ll >
#define vii vector< vi >
#define viii vector< vii >
#define pii pair< ll, ll >
#define vpii vector< pii >
#define len length()
#define pb push_back
#define mp make_pair3
#define ff first
#define ss second
#define nl cout <<  endl
#define all(ar) ar.begin(), ar.end()
#define ini(X,Y) ll X; X=Y
#define inx(X) ll X; cin >> X
#define inxy(X, Y) ll X, Y; cin >> X >> Y
#define iter(arr) for (ll i=0; i<arr.size(); i++)
#define ret return
#define cont continue
ll inf=1000000007;

ll min1(ll a, ll b, ll c)
{
	ret (min(a,min(b,c)));
}
ll k,c;

ll solve(vi &arr, vi &dp, ll n)
{
	if (n<=1)
	{
		ret 0;
	}
	if (dp[n]!=-1)
	{
		ret dp[n];
	}
	ll cost=1e18;
	for (int i=1; i<=k; i++)
	{
		if (n-i>=2)
		cost=min(abs(arr[n]-arr[n-i])*abs(arr[n]-arr[n-i])+solve(arr,dp,n-i)+c,cost);
	}
	dp[n]=cost;
	ret dp[n];
}

int main()
{
	fast;
	ll n;
	cin >> n;
	cin >> c;
	k=n-1;
	vi arr(n+2);
	arr[0]=	1e18;
	arr[1]=	1e18;
	for (ll i=2; i<n+2; i++)
	{
		cin >> arr[i];
	}
	vi dp(n+2,-1);
	dp[2]=0;
	cout << solve(arr,dp,n+1);
	ret 0;
}


Compiler output:
a.cc:112:4: error: redefinition of 'long long int inf'
  112 | ll inf=1000000007;
      |    ^~~
a.cc:33:4: note: 'long long int inf' previously defined here
   33 | ll inf=1000000007;
      |    ^~~
a.cc:114:4: error: redefinition of 'long long int min1(long long int, long long int, long long int)'
  114 | ll min1(ll a, ll b, ll c)
      |    ^~~~
a.cc:35:4: note: 'long long int min1(long long int, long long int, long long int)' previously defined here
   35 | ll min1(ll a, ll b, ll c)
      |    ^~~~
a.cc:118:4: error: redefinition of 'long long int k'
  118 | ll k,c;
      |    ^
a.cc:39:4: note: 'long long int k' previously declared here
   39 | ll k,c;
      |    ^
a.cc:118:6: error: redefinition of 'long long int c'
  118 | ll k,c;
      |      ^
a.cc:39:6: note: 'long long int c' previously declared here
   39 | ll k,c;
      |      ^
a.cc:120:4: error: redefinition of 'long long int solve(std::vector<long long int>&, std::vector<long long int>&, long long int)'
  120 | ll solve(vi &arr, vi &dp, ll n)
      |    ^~~~~
a.cc:41:4: note: 'long long int solve(std::vector<long long int>&, std::vector<long long int>&, long long int)' previously defined here
   41 | ll solve(vi &arr, vi &dp, ll n)
      |    ^~~~~
a.cc:140:5: error: redefinition of 'int main()'
  140 | int main()
      |     ^~~~
a.cc:61:5: note: 'int main()' previously defined here
   61 | int main()
      |     ^~~~