Submission #1117612

#TimeUsernameProblemLanguageResultExecution timeMemory
1117612vjudge1Building Bridges (CEOI17_building)C++17
30 / 100
3056 ms8784 KiB
//UNSTOPPABLE
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define tpii pair <pair <int,int> , int>
#define bruh cout << "NO\n"
using namespace std;
using namespace __gnu_pbds;
const int N = 3e5 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,a[N],b[N],dp[N],p[N];
int f(int x){
	return x * x;
}
void Gold(){
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];
	}
	for(int i = 1 ; i <= n ; i++){
		cin >> b[i];
		p[i] = p[i - 1] + b[i];
	}
	dp[1] = 0;
	for(int i = 2 ; i <= n ; i++){
		dp[i] = f(a[1] - a[i]) + (p[i - 1] - p[1]);
		for(int j = 1 ; j < i ; j++){
			dp[i] = min(dp[i] , f(a[i] - a[j]) + dp[j] + p[i - 1] - p[j]);
		}
//		cout << i << ' ' << dp[i] << '\n';
	}
	cout << dp[n];
//6
//3 8 7 1 6 6
//0 -1 9 1 2 0
}
signed main(/*Zhunussov Temirlan*/){
	//freopen("txt.in","r",stdin);
	//freopen("txt.out","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	srand(time(0));
	int TT = 1;
	// cin >> TT;
	for(int i = 1 ; i <= TT ; i++){
		//cout << "Case " << i << ": ";
		Gold();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...