88742024-02-02 18:17:00NagyLeoLegmesszebbi rossz sorrendű (35 pont)pypy3Runtime error 17/35107ms101280 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
base17/35
1Accepted0/050ms87636 KiB
2Runtime error0/075ms98044 KiB
3Accepted1/159ms87324 KiB
4Accepted1/148ms87412 KiB
5Accepted1/146ms87284 KiB
6Accepted1/146ms87636 KiB
7Accepted1/146ms87508 KiB
8Accepted1/157ms94224 KiB
9Accepted1/164ms96116 KiB
10Accepted1/165ms96048 KiB
11Accepted1/168ms95916 KiB
12Accepted2/290ms100248 KiB
13Accepted2/2107ms100892 KiB
14Accepted2/293ms101280 KiB
15Accepted2/281ms98480 KiB
16Runtime error0/279ms101052 KiB
17Runtime error0/270ms97496 KiB
18Runtime error0/271ms97176 KiB
19Runtime error0/268ms95176 KiB
20Runtime error0/270ms95732 KiB
21Runtime error0/270ms95480 KiB
22Runtime error0/281ms95044 KiB
23Runtime error0/270ms95020 KiB
24Runtime error0/270ms95144 KiB