201342026-01-02 15:22:46szabelrInverziócpp17Elfogadva 50/5071ms7324 KiB
// Legmesszebbi rossz sorrendű.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> szamok(n);
    vector<int> bal;
    vector<int> jobb;
    for (int i = 0; i < n; i++)
    {
        cin >> szamok[i];
    }
    int maxi = INT_MIN;
    for (int i = 0; i < n; i++)
    {
        if (szamok[i] > maxi)
        {
            maxi = szamok[i];
            bal.push_back(i);
        }
    }
    int mini = INT_MAX;
    for (int i = n-1; i >=0; i--)
    {
        if (szamok[i] < mini)
        {
            mini = szamok[i];
            jobb.push_back(i);
        }
    }
    reverse(jobb.begin(), jobb.end());
    int i = 0, j = 0;
    int best_bal=INT_MAX, best_jobb, best_dist = -1;
    while (i < bal.size() and j < jobb.size())
    {
        int idx_i = bal[i];
        int idx_j = jobb[j];
        if (szamok[idx_i] > szamok[idx_j])
        {
            int dist = idx_j - idx_i;
            if (dist > best_dist) {
                best_bal = idx_i+1;
                best_jobb = idx_j+1;
                best_dist = dist;
            }
            else if (dist == best_dist and idx_i+1<best_bal)
            {
                best_bal = idx_i+1;
                best_jobb = idx_j + 1;
            }
            j++;
        }
        else
        {
            i++;
        }
    }
    if (best_dist == -1)
        cout << -1;
    else
        cout << best_bal << " " << best_jobb;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms508 KiB
2Elfogadva0/06ms564 KiB
3Elfogadva1/11ms508 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva7/71ms316 KiB
6Elfogadva2/27ms564 KiB
7Elfogadva2/261ms2392 KiB
8Elfogadva2/261ms2548 KiB
9Elfogadva2/261ms2356 KiB
10Elfogadva2/261ms2356 KiB
11Elfogadva2/261ms2356 KiB
12Elfogadva2/259ms2356 KiB
13Elfogadva2/261ms2356 KiB
14Elfogadva2/261ms2356 KiB
15Elfogadva2/261ms2356 KiB
16Elfogadva2/263ms2396 KiB
17Elfogadva2/261ms2356 KiB
18Elfogadva2/261ms2356 KiB
19Elfogadva3/361ms2372 KiB
20Elfogadva3/361ms2392 KiB
21Elfogadva2/261ms2540 KiB
22Elfogadva2/261ms2360 KiB
23Elfogadva2/261ms2552 KiB
24Elfogadva2/271ms7324 KiB