88762024-02-02 18:21:12NagyLeoLegmesszebbi rossz sorrendű (35 pont)pypy3Runtime error 19/35111ms101504 KiB
def find_misplaced_elements(nums, n):
    max_length = -1
    first_num = 0
    second_num = 0
    minimums = [0] * n
    # minimums[-i] megmondja a leghatso i minimumat
    minimums[-1] = nums[-1]
    for i in range(n - 2, -1, -1):
        minimums[i] = min(minimums[i + 1], nums[i])
    for i in range(n - 1):
        if minimums[i + 1] >= nums[i]:
            continue
        if minimums[-1] < nums[i]:
            if n - 1 - i > max_length:
                max_length = n - 1 - i
                first_num = i
                second_num = n - 1
                continue
        lo = i + 1
        hi = n - 1
        while hi - lo > 1:
            mid = (lo + hi) // 2
            if minimums[mid] < nums[i]:
                lo = mid
            else:
                hi = mid
        if lo - i > max_length:
            max_length = lo - i
            first_num = i
            second_num = lo

    if max_length > -1:
        print(first_num + 1, second_num + 1)
    else:
        print(-1)


n = int(input())
nums = list(map(int, input().split()))

find_misplaced_elements(nums, n)
SubtaskSumTestVerdictTimeMemory
base19/35
1Accepted0/050ms87560 KiB
2Runtime error0/064ms98280 KiB
3Accepted1/161ms87884 KiB
4Accepted1/148ms87572 KiB
5Accepted1/154ms87212 KiB
6Accepted1/154ms87524 KiB
7Accepted1/154ms87584 KiB
8Accepted1/167ms94300 KiB
9Accepted1/174ms96152 KiB
10Accepted1/168ms95988 KiB
11Accepted1/179ms95952 KiB
12Accepted2/2101ms100188 KiB
13Accepted2/2111ms100908 KiB
14Accepted2/2104ms101272 KiB
15Accepted2/2101ms98452 KiB
16Accepted2/2105ms101504 KiB
17Runtime error0/282ms97848 KiB
18Runtime error0/282ms97580 KiB
19Runtime error0/278ms95496 KiB
20Runtime error0/281ms95624 KiB
21Runtime error0/281ms95996 KiB
22Runtime error0/279ms95664 KiB
23Runtime error0/276ms95392 KiB
24Runtime error0/279ms95388 KiB