182242025-10-14 19:11:17szabelrSíkság (55)cpp17Accepted 55/5534ms536 KiB
// siksag.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>

using namespace std;

int main()
{
    int n, besth = 1, sz2l, csere, bestk = 1, bestv = 1, k = 1, h = 1, v = 1, sz1 = -1, sz2 = -1, x;
    cin >> n;
    cin >> x;
    sz1 = x;
    for (int i = 2; i <= n; i++)
    {
        cin >> x;
        if (sz2 == -1)
        {
            if (x == sz1 + 1 or x == sz1 - 1) {
                sz2 = x;
                sz2l = i;
                h++;
                v = i;
                if (h > besth) {
                    besth = h;
                    bestk = k;
                    bestv = v;
                }
            }
            else if (x != sz1) {
                sz1 = x;
                k = i;
                h = 1;
                v = i;
            }
            else if (x == sz1) {
                h++;
                v = i;
                if (h > besth) {
                    besth = h;
                    bestk = k;
                    bestv = v;
                }
            }
        }
        else
        {
            if (sz1 == x or x == sz2) {
                h++;
                v = i;
                if (h > besth) {
                    besth = h;
                    bestk = k;
                    bestv = v;
                }
                if (x == sz1) {
                    csere = sz2;
                    sz2 = sz1;
                    sz1 = csere;
                    sz2l = i;

                }

            }
            else if (x == sz2 + 1)
            {
                k = sz2l;

                sz1 = sz2;
                sz2 = sz2 + 1;
                sz2l = i;
                v = i;
                h = v - k + 1;
                if (h > besth) {
                    besth = h;
                    bestk = k;
                    bestv = v;
                }
            }
            else if (x == sz2 - 1)
            {
                k = sz2l;
                sz1 = sz2;
                sz2 = sz2 - 1;
                sz2l = i;
                v = i;
                h = v - k + 1;
                if (h > besth) {
                    besth = h;
                    bestk = k;
                    bestv = v;
                }
            }
            else {
                sz1 = x;
                k = i;
                v = i;
                h = 1;
                sz2 = -1;
            }
        }
    }
    cout << besth << " " << bestk;
    return 0;
}
// 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
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/01ms500 KiB
2Accepted0/03ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms508 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted3/31ms404 KiB
8Accepted2/22ms536 KiB
9Accepted3/31ms500 KiB
10Accepted3/34ms404 KiB
11Accepted3/33ms396 KiB
12Accepted3/33ms316 KiB
13Accepted3/332ms404 KiB
14Accepted3/317ms396 KiB
15Accepted3/325ms396 KiB
16Accepted3/332ms396 KiB
17Accepted3/334ms404 KiB
18Accepted3/334ms392 KiB
19Accepted3/334ms400 KiB
20Accepted3/332ms396 KiB
21Accepted3/317ms508 KiB
22Accepted3/326ms400 KiB