#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fr first
#define sc second
const long long INF=1e17,N=2e5+6;
int h[N],c[N];
int f(int l, int r){
int val=(h[r]-h[l])*(h[r]-h[l]);
for(int i=l+1;i<r;i++)
val+=c[i];
int res=val, md=-1;
int sum=res-(h[r]-h[l])*(h[r]-h[l]);
for(int i=l+1;i<r;i++){
int tmp=(sum-c[i]+(h[l]-h[i])*(h[l]-h[i])+
(h[r]-h[i])*(h[r]-h[i]));
if(tmp<=res){
res=tmp;
md=i;
}
}
if(md==-1) return res;
return f(l,md)+f(md,r);
}
void solve(){
int n;cin>>n;
for(int i=1;i<=n;i++)
cin>>h[i];
for(int i=1;i<=n;i++)
cin>>c[i];
cout<<f(1,n);
}
main(){
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message
building.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
2652 KB |
Output is correct |
2 |
Correct |
36 ms |
2640 KB |
Output is correct |
3 |
Correct |
35 ms |
2648 KB |
Output is correct |
4 |
Correct |
33 ms |
2732 KB |
Output is correct |
5 |
Incorrect |
34 ms |
2640 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |