#include <bits/stdc++.h>
using namespace std;
#define Tupizm ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ONE exit(0);
#define nl "\n"
#define fly return
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define ppb pop_back
typedef long long ll;
typedef double db;
const int N = 1e5 + 5;
const int M = 1e9 + 7;
int n, h[N], w[N];
ll ans = 1e10;
int a[N], b[N];
int main(){
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> h[i];
}
for(int i = 1; i <= n; ++i){
cin >> w[i];
a[i] = a[i - 1] + w[i];
}
for(int i = 2; i < n; ++i){
int q = a[i - 1] + ((h[i] - h[1]) * (h[i] - h[1]));
int e = a[n - 1] - a[i] + ((h[i] - h[n]) * (h[i] - h[n]));
ans = min(ans, (ll)(q + e));
for(int j = i + 1; j <= n; ++j){
int t = a[j - 1] - a[i] + ((h[j] - h[i]) * (h[j] - h[i]));
int y = a[n - 1] - a[j] + ((h[n] - h[j]) * (h[n] - h[j]));
ans = min(ans, (ll)(q + t + y));
}
}
ans = min(ans, (ll)((h[n] - h[1]) * (h[n] - h[1]) + a[n] - a[1]));
cout << ans << nl;
ONE
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3034 ms |
1636 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |