https://codeforces.net/problemset/problem/1659/C
include <bits/stdc++.h>
/*.......................code by LegendARY...............................*/ using namespace std; using ll = long long; // my recusive solution ll Min_dist(ll capital,ll n,ll conq,ll a,ll b,vector&arr){ if(conq >= n-1){ // last wale to direct return b*(arr[n-1]-capital); } // c1 ko don't change, // c1 ko change kr do: take out the minimum; return min(b*abs(capital-arr[conq])+Min_dist(capital,n,conq+1,a,b,arr) ,a*abs(capital-arr[conq])+b*abs(arr[conq]-arr[conq+1])+Min_dist(arr[conq],n,conq+1,a,b,arr));
} //cout<<fixed<<setprecision(6) <<vv; void MYFUN(){ ll n,a,b; cin>>n>>a>>b; vectorarr(n); for(auto &it:arr) cin>>it; ll c1 =0; cout<<Min_dist(0,n,1,a,b,arr)+b*(arr[0])<<endl; } // u had to choose these three
int main(){ ll n; cin>>n; while(n--)MYFUN(); }
You manually added the conquer cost for the first city (index 0) and started recursion from index 1. This led to missing the current city's cost in the recursive steps and caused incorrect handling of the initial city.
Try this
thanks alot sir!