Submission #720326

#TimeUsernameProblemLanguageResultExecution timeMemory
720326Yell0Sequence (BOI14_sequence)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MN=1e6+2; int N,l[MN],r[MN],a[MN],is[MN]; ll ans=0; bool cmp(int i,int j) { return a[i]<a[j]; } int main() { ios::sync_with_stdio(0);cin.tie(0); cin>>N; a[0]=a[N+1]=INT_MAX; for(int i=1;i<=N;++i) { is[i]=i; l[i]=i-1; r[i]=i+1; cin>>a[i]; } sort(is+1,is+1+N,cmp); for(int x=1;x<N;++x) { r[l[is[x]]]=r[is[x]]; l[r[is[x]]]=l[is[x]]; ans+=min(a[l[is[x]]],a[r[is[x]]]); } cout<<ans<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...