88802024-02-02 18:40:16NagyLeoLegmesszebbi rossz sorrendű (35 pont)python3Elfogadva 35/35123ms37228 KiB
def find_misplaced_elements(nums, n):
    max_length = 0
    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 = max_length + i + 1
        if lo > n - 1:
            break
        hi = n - 1
        if minimums[lo] >= nums[i]:
            continue
        while hi - lo > 1:
            mid = (lo + hi) // 2
            if minimums[mid] < nums[i]:
                lo = mid
            else:
                hi = mid
        max_length = lo - i
        first_num = i
        second_num = lo

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


n = int(input())
nums = tuple(map(int, input().split()))
n = len(nums)

find_misplaced_elements(nums, n)
RészfeladatÖsszpontTesztVerdiktIdőMemória
base35/35
1Elfogadva0/018ms11284 KiB
2Elfogadva0/0120ms35108 KiB
3Elfogadva1/117ms11940 KiB
4Elfogadva1/117ms11956 KiB
5Elfogadva1/117ms12344 KiB
6Elfogadva1/117ms12376 KiB
7Elfogadva1/117ms12628 KiB
8Elfogadva1/117ms12808 KiB
9Elfogadva1/120ms13104 KiB
10Elfogadva1/120ms13384 KiB
11Elfogadva1/121ms13836 KiB
12Elfogadva2/261ms22336 KiB
13Elfogadva2/264ms23604 KiB
14Elfogadva2/267ms24996 KiB
15Elfogadva2/248ms19872 KiB
16Elfogadva2/271ms25512 KiB
17Elfogadva2/287ms29324 KiB
18Elfogadva2/297ms32644 KiB
19Elfogadva2/2105ms33200 KiB
20Elfogadva2/2107ms34304 KiB
21Elfogadva2/2115ms37036 KiB
22Elfogadva2/2115ms37220 KiB
23Elfogadva2/2123ms36980 KiB
24Elfogadva2/2122ms37228 KiB