Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=200010;
const ll mod=1e9+7;

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(ll i=(ll)m ; i < (ll) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

//オンライン

template<typename T,const T id>
struct ConvexHullTrick{
    struct Line{
        T a,b;
        Line(T a=0,T b=0):a(a),b(b){}
        T get(T x){return -(x-a)*(x-a)-b;}
    };

    struct Node{
        Line l;
        Node *lhs,*rhs;
        Node(Line l):l(l),lhs(nullptr),rhs(nullptr){}
    };

    const T mi,ma;
    Node* root=nullptr;

    ConvexHullTrick(T mi=0,T ma=1<<30):mi(mi),ma(ma){}
    Node* insert(Node* p,T lb,T ub,Line& l){
        if(!p)return new Node(l);
        if(p->l.get(lb)>=l.get(lb)&&p->l.get(ub)>=l.get(ub))return p;
        if(p->l.get(lb)<=l.get(lb)&&p->l.get(ub)<=l.get(ub)){
            p->l = l;
            return p;
        }
        T mid=(lb+ub)/2;
        if(p->l.get(mid)<l.get(mid))swap(p->l , l);
        if(p->l.get(lb)<=l.get(lb)){
            p->lhs=insert(p->lhs,lb,mid,l);
        }
        else {
            p->rhs=insert(p->rhs,mid,ub,l);
        }
        return p;

    }
    void insert(T a,T b){
        Line l(a,b);
        root=insert(root,mi,ma,l);
    }

    void insert(Line l){
        root=insert(root,mi,ma,l);
    }
    T query(Node* p,T lb,T ub,T t){
        if(!p)return id;
        if(lb==ub)return p->l.get(t);
        T mid=(lb+ub)/2;
        if(t<=mid)return max(p->l.get(t),query(p->lhs,lb,mid,t));
        else return max(p->l.get(t),query(p->rhs,mid,ub,t));
    }

    T query(T x){
        return query(root,mi,ma,x);
    }
};


int main(){
    int n;cin>>n;
    ll c;cin>>c;
    ConvexHullTrick<ll,-longinf> cht; 
    ll ret=0; 
    rep(i,n){
        ll h;cin>>h;
        if(i)ret=-cht.query(h);
        cht.insert(h,c+ret);
    }  
    cout<<ret<<endl;
    return 0;
}


Compiler output:
a.cc:32:9: warning: "REP" redefined
   32 | #define REP(i,m,n) for(ll i=(ll)m ; i < (ll) n ; ++i )
      |         ^~~
a.cc:8:9: note: this is the location of the previous definition
    8 | #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
      |         ^~~
a.cc:37:11: error: redefinition of 'const int inf'
   37 | const int inf=1e9+7;
      |           ^~~
a.cc:6:11: note: 'const int inf' previously defined here
    6 | const int inf=1e9+7;
      |           ^~~
a.cc:38:10: error: redefinition of 'const ll longinf'
   38 | const ll longinf=1LL<<60 ;
      |          ^~~~~~~
a.cc:7:10: note: 'const ll longinf' previously defined here
    7 | const ll longinf=1LL<<60;
      |          ^~~~~~~
a.cc:39:10: error: redefinition of 'const ll mod'
   39 | const ll mod=1e9+7 ;
      |          ^~~
a.cc:16:10: note: 'const ll mod' previously defined here
   16 | const ll mod=1e9+7;
      |          ^~~