Submission #1153829

#TimeUsernameProblemLanguageResultExecution timeMemory
1153829WongYiKaiPo (COCI21_po)C++20
70 / 70
6 ms840 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	ll n;
    cin >> n;
    ll mn = 2000000000;
    stack<ll> s;
    ll count=0;
    for (int i=0;i<n;i++){
        ll curr;
        cin >> curr;
        mn = min(mn,curr);
        while (!s.empty() && s.top()>curr) {
            count++;
            s.pop();
        }
        if (s.empty() || s.top() != curr) s.push(curr);
    }
    count += s.size();
    if (mn==0) count--;
    cout << count;
}
#Verdict Execution timeMemoryGrader output
Fetching results...