149012025-02-06 16:43:46PKBLegcsalódottabb versenyző (75 pont)cpp14Wrong answer 45/7514ms1280 KiB
#include <iostream>
#include <vector>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> score(n);
    for (int i = 0; i < n; i++){
        cin >> score[i];
    }


    vector<int> nextGreater(n, -1);
    vector<int> st;

    for (int i = 0; i < n; i++){
        while (!st.empty() && score[i] > score[st.back()]){
            nextGreater[st.back()] = i;
            st.pop_back();
        }
        st.push_back(i);
    }

    int maxDuration = -1;
    int resultIndex = -1;
    for (int i = 0; i < n; i++){
        if (nextGreater[i] != -1) {
            int duration = nextGreater[i] - i;
            if (duration > maxDuration || (duration == maxDuration && i < resultIndex)) {
                maxDuration = duration;
                resultIndex = i;
            }
        }
    }

    if(resultIndex == -1)
        cout << -1;
    else
        cout << resultIndex + 1;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base45/75
1Accepted0/01ms316 KiB
2Wrong answer0/014ms1076 KiB
3Accepted5/51ms316 KiB
4Accepted5/51ms316 KiB
5Accepted5/51ms316 KiB
6Accepted5/51ms508 KiB
7Wrong answer0/51ms508 KiB
8Accepted5/51ms316 KiB
9Accepted5/51ms316 KiB
10Wrong answer0/51ms316 KiB
11Accepted5/51ms316 KiB
12Accepted5/51ms316 KiB
13Accepted5/514ms1076 KiB
14Wrong answer0/514ms1076 KiB
15Wrong answer0/514ms1088 KiB
16Wrong answer0/514ms1084 KiB
17Wrong answer0/514ms1280 KiB