81072024-01-12 13:44:34tamasmarkLegmesszebbi rossz sorrendű (35 pont)cpp17Hibás válasz 24/3550ms4808 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) return 1;
    else return 0;

}
int k,v,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;
        }
    }
    cout << k << " " << v;
    return 0;
}
/*
10
7 2 4 17 6 5 10 10 18 19
*/
// 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
base24/35
1Elfogadva0/03ms1816 KiB
2Elfogadva0/050ms3356 KiB
3Hibás válasz0/13ms2360 KiB
4Elfogadva1/13ms2464 KiB
5Elfogadva1/13ms2708 KiB
6Elfogadva1/13ms2588 KiB
7Elfogadva1/13ms2588 KiB
8Elfogadva1/13ms2596 KiB
9Elfogadva1/13ms2676 KiB
10Elfogadva1/14ms2688 KiB
11Elfogadva1/14ms2908 KiB
12Hibás válasz0/219ms3568 KiB
13Hibás válasz0/221ms3936 KiB
14Hibás válasz0/224ms4112 KiB
15Hibás válasz0/216ms3624 KiB
16Hibás válasz0/224ms4036 KiB
17Elfogadva2/235ms4168 KiB
18Elfogadva2/239ms4556 KiB
19Elfogadva2/243ms4808 KiB
20Elfogadva2/246ms4768 KiB
21Elfogadva2/248ms4752 KiB
22Elfogadva2/250ms4748 KiB
23Elfogadva2/239ms4752 KiB
24Elfogadva2/239ms4748 KiB