66772023-12-15 22:29:29KezdőSípálya (55 pont)python3Time limit exceeded 21/55486ms30348 KiB
from sys import stdin
from bisect import bisect

def main():
    N,K = [int(i) for i in input().split()]
    C = [0] + [int(i) for i in stdin.readline().split()]
    s = [0]*(N+1)
    for i in range(N):
        C[i+1] += i
        s[i+1] = s[i] + C[i+1]
    db = []
    for i in range(1,K+1):
        db.insert(bisect(db,C[i]),C[i])
    maxi = db[-1]
    mine = maxi * K - (s[K] - s[0])
    for i in range(1,N-K+1):
        if C[i] != C[i+K]:
            db.remove(C[i])
            db.insert(bisect(db,C[i+K]),C[i+K])
        maxi = db[-1]
        m = s[i+K] - s[i]
        e = maxi * K - m
        if e < mine:
            mine = e
    print(mine)    
main()
SubtaskSumTestVerdictTimeMemory
base21/55
1Accepted0/017ms11472 KiB
2Accepted0/018ms11940 KiB
3Accepted2/219ms12240 KiB
4Accepted2/220ms12564 KiB
5Accepted2/220ms12592 KiB
6Accepted2/220ms12796 KiB
7Accepted3/320ms13328 KiB
8Accepted1/152ms15340 KiB
9Accepted1/152ms15664 KiB
10Accepted1/154ms15688 KiB
11Accepted1/1155ms15744 KiB
12Accepted1/1135ms15904 KiB
13Accepted1/1307ms15828 KiB
14Accepted2/2312ms15928 KiB
15Accepted2/2131ms16260 KiB
16Time limit exceeded0/2451ms29368 KiB
17Time limit exceeded0/2465ms29368 KiB
18Time limit exceeded0/2469ms27976 KiB
19Time limit exceeded0/3469ms29800 KiB
20Time limit exceeded0/2469ms29652 KiB
21Time limit exceeded0/2469ms28496 KiB
22Time limit exceeded0/2449ms28464 KiB
23Time limit exceeded0/2472ms29824 KiB
24Time limit exceeded0/2462ms28348 KiB
25Time limit exceeded0/2465ms29752 KiB
26Time limit exceeded0/2486ms29988 KiB
27Time limit exceeded0/2477ms28548 KiB
28Time limit exceeded0/3474ms28508 KiB
29Time limit exceeded0/3481ms28852 KiB
30Time limit exceeded0/3474ms30348 KiB