#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N=1e6+10;
struct line{
ll m,b;
line(ll mm,ll bb){
m=mm; b=bb;
}
ll eval(ll x){
return m*x+b;
}
long double intersect(line l){
return (long double)(b-l.b)/(l.m-m);
}
};
ll val[MAX_N];
int main(){
int n; cin>>n;
for(int i=0;i<n;i++){
cin>>val[i+1];
}
deque<line> dq;
dq.push_front({0,0});
ll ans=0;
for(int i=1;i<=n;i++){
int t=dq.size();
line nl={-i,ans};
while(t>=2 && dq[t-1].eval(val[i])>=dq[t-2].eval(val[i])){
t--; dq.pop_back();
}
ll f=dq.back().eval(val[i])+val[i]*(n+1);
ans=f;
while(dq.size()>=2 && nl.intersect(dq[0])>=dq[0].intersect(dq[1]))
dq.pop_front();
dq.push_front(nl);
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
399 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |