제출 #1131661

#제출 시각아이디문제언어결과실행 시간메모리
1131661Champ_NamanBuilding Bridges (CEOI17_building)C++20
30 / 100
3094 ms2628 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define nl '\n'

const int N = 1e5+1;
int dp[N];

inline void solve(){
   int n;
   cin>>n;
   int h[n+1], w[n+1], pre[n+1];
   pre[0] = 0;
   for(int i=1; i<=n; i++) cin>>h[i];
   for(int i=1; i<=n; i++) cin>>pre[i], pre[i] += pre[i-1];

   for(int i=2; i<=n; i++){
      dp[i] = 1e18;
      for(int j=i-1; j>0; j--){
         dp[i] = min(dp[i], dp[j] + (h[i] - h[j])*(h[i] - h[j]) + pre[i-1] - pre[j]);
      }
   }

   cout<<dp[n];
}

signed main(){
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);cout.tie(NULL);

   int t = 1;
   //cin>>t;
   while(t--) solve();

   return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...