117352024-11-08 14:48:25balintLeggyorsabb pénzkeresés (50)python3Wrong answer 6/50301ms17576 KiB
def main():
    N, P = map(int, input().split())
    nums = list(map(int, input().split()))

    lst = []

    for i in range(N):
        lst.append((nums[i], i))
    lst.sort(reverse=True)

    min_length = N
    for peak, idx in lst:
        suma = peak
        left_idx = idx - 1
        right_idx = idx + 1
        length = 1
        while suma < P and length < min_length:
            if left_idx < 0:
                suma += nums[right_idx]
                right_idx += 1
            elif right_idx > N - 1:
                suma += nums[left_idx]
                left_idx -= 1

            else:
                if nums[left_idx] > nums[right_idx]:
                    suma += nums[left_idx]
                    left_idx -= 1
                else:
                    suma += nums[right_idx]
                    right_idx += 1
            length += 1
        if length < min_length:
            min_length = length
    print(min_length)


main()
SubtaskSumTestVerdictTimeMemory
base6/50
1Wrong answer0/016ms3312 KiB
2Time limit exceeded0/0280ms17576 KiB
3Accepted2/216ms3128 KiB
4Accepted2/216ms3120 KiB
5Accepted2/217ms3028 KiB
6Time limit exceeded0/2300ms4356 KiB
7Time limit exceeded0/2300ms4568 KiB
8Time limit exceeded0/2293ms4408 KiB
9Time limit exceeded0/2287ms4468 KiB
10Time limit exceeded0/2282ms4408 KiB
11Time limit exceeded0/2228ms17352 KiB
12Time limit exceeded0/2300ms17444 KiB
13Time limit exceeded0/2291ms17428 KiB
14Time limit exceeded0/2300ms17424 KiB
15Time limit exceeded0/2289ms17424 KiB
16Time limit exceeded0/2300ms17424 KiB
17Time limit exceeded0/2282ms17432 KiB
18Time limit exceeded0/2300ms17504 KiB
19Time limit exceeded0/2279ms17540 KiB
20Time limit exceeded0/2301ms17428 KiB
21Time limit exceeded0/2291ms17416 KiB
22Time limit exceeded0/2300ms17432 KiB
23Time limit exceeded0/2289ms17356 KiB
24Time limit exceeded0/2301ms17412 KiB
25Time limit exceeded0/2275ms17540 KiB
26Time limit exceeded0/2300ms17504 KiB
27Time limit exceeded0/2284ms17376 KiB