Submission #521924

#TimeUsernameProblemLanguageResultExecution timeMemory
521924DanerZeinDischarging (NOI20_discharging)C++14
0 / 100
692 ms22084 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N=1e6; const int MAX_P=MAX_N*4; const int MAX=1e9; int val[MAX_N]; int tr[MAX_P]; void init(int node,int a,int b){ if(a==b){ tr[node]=val[a]; return; } int mid=(a+b)/2,le=2*node+1,ri=2*node+2; init(le,a,mid); init(ri,mid+1,b); tr[node]=max(tr[le],tr[ri]); } int query(int node,int a,int b,int l,int r){ if(b<l || a>r) return -MAX; if(l<=a && r>=b) return tr[node]; int mid=(a+b)/2,le=2*node+1,ri=2*node+2; return max(query(le,a,mid,l,r),query(ri,mid+1,b,l,r)); } int main(){ int n; cin>>n; for(int i=0;i<n;i++){ int a; cin>>a; val[i]=a; } init(0,0,n-1); ll res=query(0,0,n-1,0,n-1)*n; for(int i=1;i<n-1;i++){ ll q1=query(0,0,n-1,i,n-1); ll q2=query(0,0,n-1,0,i-1); ll d=n-i; res=min(res,q1*d+q2*n); } cout<<res<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...