66762023-12-15 22:27:26KezdőSípálya (55 pont)python3Time limit exceeded 21/55490ms59960 KiB
from sys import stdin

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):
        if C[i] in db:
            db[C[i]] += 1
        else:
            db[C[i]] = 1
    maxi = max(db.keys())
    mine = maxi * K - (s[K] - s[0])
    for i in range(1,N-K+1):
        if C[i] != C[i+K]:
            db[C[i]] -= 1
            if db[C[i]] == 0:
                del db[C[i]]
            if C[i+K] in db:
                db[C[i+K]] += 1
            else:
                db[C[i+K]] = 1
        maxi = max(db.keys())
        m = s[i+K] - s[i]
        e = maxi * K - m
        if e < mine:
            mine = e
    print(mine)    
main()
SubtaskSumTestVerdictTimeMemory
base21/55
1Accepted0/017ms11364 KiB
2Accepted0/017ms11432 KiB
3Accepted2/219ms12044 KiB
4Accepted2/220ms12160 KiB
5Accepted2/221ms12536 KiB
6Accepted2/225ms12736 KiB
7Accepted3/324ms12732 KiB
8Accepted1/1119ms14968 KiB
9Accepted1/1138ms15232 KiB
10Accepted1/1156ms15304 KiB
11Accepted1/139ms15132 KiB
12Accepted1/137ms14984 KiB
13Accepted1/143ms15236 KiB
14Accepted2/243ms15564 KiB
15Accepted2/239ms15760 KiB
16Time limit exceeded0/2479ms59960 KiB
17Time limit exceeded0/2474ms29540 KiB
18Time limit exceeded0/2476ms28520 KiB
19Time limit exceeded0/3481ms29712 KiB
20Time limit exceeded0/2481ms29756 KiB
21Time limit exceeded0/2477ms28388 KiB
22Time limit exceeded0/2462ms28476 KiB
23Time limit exceeded0/2481ms29872 KiB
24Time limit exceeded0/2460ms28680 KiB
25Time limit exceeded0/2449ms29888 KiB
26Time limit exceeded0/2476ms30100 KiB
27Time limit exceeded0/2469ms28884 KiB
28Time limit exceeded0/3472ms29032 KiB
29Time limit exceeded0/3490ms29004 KiB
30Time limit exceeded0/3481ms30168 KiB