Language: C++

  #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define f first
#define s second
#define mp make_pair
#define SZ(x) ((int)(x.size()))
#define FOI(i, a, n) for(int i = int(a); i <= int(n); i++)
#define FOD(i, a, n) for(int i = int(a); i >= int(n); i--)
#define IN(x, y) ((y).find(x) != (y).end())
#define ALL(t) t.begin(),t.end()
#define MSET(tabl,i) memset(tabl, i, sizeof(tabl))
#define PSET(x,y) fixed<<setprecision(y)<<lf(x)
#define DBG(c) cout << #c << " = " << c << endl;
#define Rtime1 ((double)clock()/(double)CLOCKS_PER_SEC)
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


typedef long long ll;
typedef long double lf;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < int > vi;
typedef vector<vi> vvi;
typedef complex<double> base;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const int N = 2e5 + 5;
const int lgN = 1e6+5;
const ll MOD = 1e9+7;
const ll MOD2 = 1299709;
const ll MOD3 = 1e9 + 9;
const lf pi = 3.141592653589793238462643383;
const ll IMAX = 4e18 + 5; 
const double PI = 3.141592653589793;


template<class T>
using max_pq = priority_queue<T>;
template<class T>
using min_pq = priority_queue<T,vector<T>,greater<T>>; 
template<class T>
using OST = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll x,y;
template<class T> T gcd(T a,T b){ if(a==0) {x=0,y=1; return b;}T gc=gcd(b%a,a);T temp;temp=x;x=y-(b/a)*temp;y=temp;return gc;}

//(a^x)%m   
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; } 

ll h[N];
ll dp[N];
vector< pair<ll, int> > nodes;


ll calc(int i, int j){
    ll c = nodes[i].f + (h[j]-h[nodes[i].s])*(h[j]-h[nodes[i].s]);
    return c;
}

ll solve(int in){
    int l = 0, r = nodes.size()-1;
    if( r - l < 500)
    {
        FOI(i,l,r){
        ll c1 = nodes[i].f + (h[in]-h[nodes[i].s])*(h[in]-h[nodes[i].s]);
        c = min(c1, c);
        return c;
    }

    FOI(i, 1, 100){
        int mid1 = l + (r - l)/3;
        int mid2 = l + 2*(r - l)/3;
        ll c1 = nodes[mid1].f + (h[in]-h[nodes[mid1].s])*(h[in]-h[nodes[mid1].s]);
        ll c2 = nodes[mid2].f + (h[in]-h[nodes[mid2].s])*(h[in]-h[nodes[mid2].s]);
        if(c1 < c2)
            r = mid2;
        else if(c1 > c2)
            l = mid1;
        else 
    }
    ll c = IMAX;
    FOI(i,l,r){
        ll c1 = nodes[i].f + (h[in]-h[nodes[i].s])*(h[in]-h[nodes[i].s]);
        c = min(c1, c);
    }
    return c;

}

void insert(ll co,int in){
    while(nodes.size()>0 && nodes[nodes.size()-1].f >= co)
        nodes.pop_back();
    nodes.push_back({co, in});
}

int main(){
    sync
    int n;
    cin>>n;
    ll c;
    cin>>c;
    FOI(i,1,n)
    cin>>h[i];

    dp[1] = 0;
    nodes.pb({0, 1});

    FOI(i,2,n){
        ll cost = solve(i);
        dp[i] = cost + c;
        insert(dp[i], i);
    }

    cout<<dp[n]<<endl;
}



Compiler output:
a.cc: In function 'll solve(int)':
a.cc:87:9: error: 'c' was not declared in this scope; did you mean 'c1'?
   87 |         c = min(c1, c);
      |         ^
      |         c1
a.cc:101:5: error: expected primary-expression before '}' token
  101 |     }
      |     ^
a.cc:111:26: error: a function-definition is not allowed here before '{' token
  111 | void insert(ll co,int in){
      |                          ^
a.cc:117:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  117 | int main(){
      |         ^~
a.cc:117:9: note: remove parentheses to default-initialize a variable
  117 | int main(){
      |         ^~
      |         --
a.cc:117:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:117:11: error: a function-definition is not allowed here before '{' token
  117 | int main(){
      |           ^
a.cc:136:2: error: expected '}' at end of input
  136 | }
      |  ^
a.cc:81:17: note: to match this '{'
   81 | ll solve(int in){
      |                 ^