Submission #720326

# Submission time Handle Problem Language Result Execution time Memory
720326 2023-04-08T03:24:51 Z Yell0 Sequence (BOI14_sequence) C++17
0 / 100
1 ms 340 KB
#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 time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -