81092024-01-12 13:47:44tamasmarkLegmesszebbi rossz sorrendű (35 pont)cpp17Hibás válasz 34/3550ms5684 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,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
base34/35
1Elfogadva0/03ms1848 KiB
2Elfogadva0/050ms3392 KiB
3Hibás válasz0/13ms2252 KiB
4Elfogadva1/13ms2492 KiB
5Elfogadva1/13ms2612 KiB
6Elfogadva1/13ms2804 KiB
7Elfogadva1/13ms3012 KiB
8Elfogadva1/13ms3172 KiB
9Elfogadva1/13ms3184 KiB
10Elfogadva1/14ms3192 KiB
11Elfogadva1/14ms3548 KiB
12Elfogadva2/219ms3816 KiB
13Elfogadva2/223ms4340 KiB
14Elfogadva2/224ms4428 KiB
15Elfogadva2/216ms4012 KiB
16Elfogadva2/225ms4512 KiB
17Elfogadva2/235ms4892 KiB
18Elfogadva2/239ms5372 KiB
19Elfogadva2/243ms5484 KiB
20Elfogadva2/246ms5452 KiB
21Elfogadva2/250ms5580 KiB
22Elfogadva2/250ms5684 KiB
23Elfogadva2/239ms5580 KiB
24Elfogadva2/239ms5584 KiB