fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define int ll
  4. #define pb push_back
  5. #define INF 1e18
  6. #define MOD 1000000007
  7. #define mp make_pair
  8. #define REP(i,n) for (int i = 0; i < n; i++)
  9. #define FOR(i,a,b) for (int i = a; i < b; i++)
  10. #define REPD(i,n) for (int i = n-1; i >= 0; i--)
  11. #define FORD(i,a,b) for (int i = a; i >= b; i--)
  12. #define umap unordered_map
  13. #define pii pair<int,int>
  14. #define F first
  15. #define S second
  16. #define mii map<int,int>
  17. #define vi vector<int>
  18. #define vvi vector<vi>
  19. #define itr :: iterator it
  20. #define all(v) v.begin(),v.end()
  21. #define WL(t) while(t--)
  22. #define gcd(a,b) __gcd((a),(b))
  23. #define lcm(a,b) ((a)*(b))/gcd((a),(b))
  24. #define out(x) cout << #x << " is " << x <<"\n"
  25. #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  26.  
  27. using namespace std;
  28.  
  29. void solve()
  30. {
  31. int n, c;
  32. cin>>n>>c;
  33. int h[n], dp[n];
  34. REP(i, n)
  35. cin>>h[i];
  36. REP(i, n)
  37. dp[i]=LONG_MAX;
  38. dp[0]=0;
  39. REP(i, n)
  40. {
  41. FORD(j, i-1, 0)
  42. {
  43. dp[i]=min(dp[i], dp[j]+(h[i]-h[j])*(h[i]-h[j])+c);
  44. }
  45. }
  46. cout<<dp[n-1];
  47. }
  48. signed main()
  49. {
  50. FastIO
  51. #ifndef ONLINE_JUDGE
  52. freopen(fi, "r", stdin);
  53. freopen(fo, "w", stdout);
  54. #else
  55. // online submission
  56. #endif
  57. int t=1;
  58. //cin>>t;
  59. WL(t){
  60. solve();
  61. if(t!=0)
  62. cout<<"\n";
  63. }
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 5624KB
stdin
5 6
1 2 3 4 5
stdout
20