117342024-11-08 14:24:09balintLeggyorsabb pénzkeresés (50)python3Wrong answer 8/50300ms14668 KiB
def main():
    N, P = map(int, input().split())
    nums = list(map(int, input().split()))

    lst = sorted(list(set(nums)), reverse=True)
    dictt = {key: -1 for key in lst}
    for i in range(N):
        dictt[nums[i]] = i

    min_length = N
    for peak, idx in dictt.items():
        suma = peak
        left_idx = idx - 1
        right_idx = idx + 1
        length = 1
        while suma < P:
            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
base8/50
1Wrong answer0/017ms3128 KiB
2Time limit exceeded0/0286ms14608 KiB
3Accepted2/216ms3128 KiB
4Accepted2/217ms3320 KiB
5Accepted2/217ms3172 KiB
6Time limit exceeded0/2280ms5024 KiB
7Time limit exceeded0/2279ms4664 KiB
8Time limit exceeded0/2300ms4796 KiB
9Time limit exceeded0/2289ms4792 KiB
10Time limit exceeded0/2282ms4664 KiB
11Accepted2/265ms14620 KiB
12Time limit exceeded0/2300ms14620 KiB
13Time limit exceeded0/2287ms14616 KiB
14Time limit exceeded0/2284ms14620 KiB
15Time limit exceeded0/2277ms14616 KiB
16Time limit exceeded0/2300ms14620 KiB
17Time limit exceeded0/2282ms14620 KiB
18Time limit exceeded0/2287ms14620 KiB
19Time limit exceeded0/2300ms14668 KiB
20Time limit exceeded0/2289ms14620 KiB
21Time limit exceeded0/2287ms14580 KiB
22Time limit exceeded0/2287ms14620 KiB
23Time limit exceeded0/2286ms14620 KiB
24Time limit exceeded0/2280ms14616 KiB
25Time limit exceeded0/2287ms14620 KiB
26Time limit exceeded0/2291ms14616 KiB
27Time limit exceeded0/2275ms14620 KiB