Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <sstream>
#include <list>
 
using namespace std;
 
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front
 
 
typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
 
 
const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
 
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
  
int main(){
  int n,c;
  cin>>n>>c;
  vector<int> h(n);
  rep(i,n) cin>>h[i];
  vector<int> dp(n+1);
  int x;
  
  for(int i=2;i<n+1;i++){
    x=dp[i-1]+pow(abs(h[i-1]-h[i-2]),2)+c;
    for(int j=2;j<n+1&&i-j-1>=0;j++){
      x=min(dp[i-j]+pow(abs(h[i-1]-h[i-j-1]),2)+c,x);
    }
    dp[i]=x;
  }
  
  cout<<dp[n]<<endl;
}
      
      
      
  
  
  
  
  

 


Compiler output:
a.cc: In function 'int main()':
a.cc:50:12: error: no matching function for call to 'min(__gnu_cxx::__promote<double>::__type, int&)'
   50 |       x=min(dp[i-j]+pow(abs(h[i-1]-h[i-j-1]),2)+c,x);
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:4:
/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:50:12: note:   deduced conflicting types for parameter 'const _Tp' ('double' and 'int')
   50 |       x=min(dp[i-j]+pow(abs(h[i-1]-h[i-j-1]),2)+c,x);
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:11:
/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:50:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'double'
   50 |       x=min(dp[i-j]+pow(abs(h[i-1]-h[i-j-1]),2)+c,x);
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~