#include <bits/stdc++.h>
using namespace std;
int h[100001];
int w[100001];
long long f[100001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i=0;i<n;i++)
{
cin >> h[i];
f[i]=1000000000000000000;
}
long long tot=0;
for(int i=0;i<n;i++)
{
cin >> w[i];
tot+=w[i];
}
f[0]=-w[0];
for(int i=1;i<n;i++)
{
for(int j=0;j<i;j++)
{
f[i]=min(f[i],f[j]+(h[i]-h[j])*(h[i]-h[j])-w[i]);
}
}
cout << tot+f[n-1];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3052 ms |
2772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Execution timed out |
3052 ms |
2772 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |