Submission #1153775

#TimeUsernameProblemLanguageResultExecution timeMemory
1153775YSH2020Po (COCI21_po)C++20
20 / 70
22 ms840 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n; cin >> n;
  int a[n+1]; for (int i = 0; i < n; i++) cin >> a[i];
  stack<int> x;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    while (x.size() > 0 and x.top() >= a[i]) {
      if (x.top() != a[i]) ans += 1;

      x.pop();
    }
    x.push(a[i]);
  }
  while (x.size() > 0) {
    ans++;
    x.pop();
  }
  cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...