81132024-01-12 13:50:19tamasmarkLegmesszebbi rossz sorrendű (35 pont)cpp17Elfogadva 35/3552ms4628 KiB
// legmessz ross sorrendu.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

struct adat
{
    int ertek, index;
};
bool hasonlit(adat a, adat b)
{
    if (a.ertek == b.ertek)
    {
        if (a.index > b.index) return 1;
        else return 0;
    }
    else if (a.ertek > b.ertek) return 1;
    else return 0;

}
int k=0,v=0,tav;
adat maxi;
int main()
{
    int n;
    cin >> n;
    vector<adat>x(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        cin >> x[i].ertek;
        x[i].index = i;
    }
    sort(x.begin()+1, x.end(), hasonlit);
    maxi.ertek=x[1].ertek;
    maxi.index = x[1].index;
    for (int i = 2; i <= n - 1; ++i)
    {
        if (maxi.index < x[i].index)
        {
            if (x[i].index - maxi.index > tav)
            {
                tav = x[i].index - maxi.index;
                k = maxi.index;
                v = x[i].index;
            }
            else if (x[i].index - maxi.index == tav && maxi.index<k)
            {
                k = maxi.index;
                v = x[i].index;
            }
        }
        else if (maxi.index > x[i].index)
        {
            maxi.ertek = x[i].ertek;
            maxi.index = x[i].index;
        }
    }
    if (k && v) cout << k << " " << v;
    else cout << -1;
    return 0;
}
/*
10
1 2 3 4 5 6 7 8 9 10
*/
// 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
base35/35
1Elfogadva0/03ms1940 KiB
2Elfogadva0/052ms3392 KiB
3Elfogadva1/13ms2228 KiB
4Elfogadva1/13ms2344 KiB
5Elfogadva1/13ms2416 KiB
6Elfogadva1/13ms2660 KiB
7Elfogadva1/13ms2628 KiB
8Elfogadva1/13ms2764 KiB
9Elfogadva1/13ms3128 KiB
10Elfogadva1/14ms3008 KiB
11Elfogadva1/14ms3084 KiB
12Elfogadva2/219ms3372 KiB
13Elfogadva2/223ms3636 KiB
14Elfogadva2/224ms3768 KiB
15Elfogadva2/216ms3248 KiB
16Elfogadva2/224ms3768 KiB
17Elfogadva2/235ms4044 KiB
18Elfogadva2/241ms4288 KiB
19Elfogadva2/245ms4284 KiB
20Elfogadva2/246ms4540 KiB
21Elfogadva2/250ms4624 KiB
22Elfogadva2/250ms4628 KiB
23Elfogadva2/237ms4628 KiB
24Elfogadva2/239ms4628 KiB