fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;using ll=long long;
  3. int main(){ios::sync_with_stdio(0);cin.tie(0);
  4. int N;cin>>N;vector<ll>T(N),c(N,4e18);priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<>>q;
  5. for(int i=0;i<N;i++){cin>>T[i];c[i]=T[i];q.push({c[i],i});}
  6. while(!q.empty()){
  7. auto [t,u]=q.top();q.pop();if(t!=c[u])continue;
  8. for(int d:{-1,1}){
  9. int v=u+d;if(v<0||v>=N)continue;
  10. ll x=t+T[v]/2;if(x<c[v]){c[v]=x;q.push({x,v});}
  11. int w=v+(d==1?-1:1);if(w>=0&&w<N&&c[w]<4e18){
  12. x=max(t,c[w])+T[v]/4;if(x<c[v]){c[v]=x;q.push({x,v});}
  13. }
  14. }
  15. }
  16. cout<<*max_element(c.begin(),c.end());
  17. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
1 8 20
stdout
8