88522024-02-02 12:45:21körteSípálya (55 pont)python3Time limit exceeded 4/55470ms132212 KiB
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
e = []
s = []

def legnagyobb(lista):
    lnagyobb = 0
    poz = []
    for i in range(len(lista)):
        if lista[i] > lnagyobb:
            lnagyobb = lista[i]
            poz.append(i)
    return lnagyobb, poz[-1]

for i in range(N-K+1):
    e.append(H[i:K+i])
    s.append(H[i:K+i])
for i in range(N-K+1):
    for j in range(K):
        e[i][j] = (legnagyobb(e[i])[0] + legnagyobb(e[i])[1] - j)

for i in range(N-K+1):
    for j in range(K):
        e[i][j] -= s[i][j]
minimum = sum(e[0])
for i in range(N-K+1):
    if sum(e[i]) < minimum:
        minimum = sum(e[i])
print(minimum)

SubtaskSumTestVerdictTimeMemory
base4/55
1Accepted0/017ms11296 KiB
2Accepted0/017ms11724 KiB
3Accepted2/234ms12580 KiB
4Accepted2/254ms13168 KiB
5Time limit exceeded0/2463ms7084 KiB
6Time limit exceeded0/2470ms7944 KiB
7Time limit exceeded0/3467ms7920 KiB
8Runtime error0/1152ms132212 KiB
9Runtime error0/1158ms132056 KiB
10Runtime error0/1143ms131704 KiB
11Runtime error0/1127ms131728 KiB
12Runtime error0/1116ms131616 KiB
13Runtime error0/1115ms131784 KiB
14Runtime error0/2128ms131384 KiB
15Runtime error0/2126ms131288 KiB
16Runtime error0/2145ms131220 KiB
17Runtime error0/2129ms131060 KiB
18Runtime error0/2128ms131048 KiB
19Runtime error0/3116ms131116 KiB
20Runtime error0/2120ms131072 KiB
21Runtime error0/2119ms130744 KiB
22Runtime error0/2120ms130644 KiB
23Runtime error0/2133ms130252 KiB
24Runtime error0/2136ms130480 KiB
25Runtime error0/2122ms130540 KiB
26Runtime error0/2123ms130352 KiB
27Runtime error0/2128ms130432 KiB
28Runtime error0/3128ms130296 KiB
29Runtime error0/3128ms130404 KiB
30Runtime error0/3134ms130280 KiB