Submission #3601125


Source Code Expand

from bisect import bisect_left
N, K = map(int, input().split())
x = [int(s) for s in input().split()]

izero = bisect_left(x, 0)
zpos = x[izero:]
neg = [-v for v in reversed(x[:izero])]

ans = 1000000000
if len(neg) >= K and ans > neg[K - 1]:
    ans = neg[K - 1]
if len(zpos) >= K and ans > zpos[K - 1]:
    ans = zpos[K - 1]
for lenneg in range(max(1, K - len(zpos)), min(K - 1, len(neg)) + 1):
    cand = 2 * neg[lenneg - 1] + zpos[K - lenneg - 1]
    if ans > cand:
        ans = cand
    cand = neg[lenneg - 1] + 2 * zpos[K - lenneg - 1]
    if ans > cand:
        ans = cand
print(ans)

Submission Info

Submission Time
Task C - Candles
User cexen
Language Python (3.4.3)
Score 300
Code Size 613 Byte
Status AC
Exec Time 86 ms
Memory 14372 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 12
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt
Case Name Status Exec Time Memory
0_00.txt AC 18 ms 3188 KB
0_01.txt AC 17 ms 3064 KB
0_02.txt AC 17 ms 3064 KB
0_03.txt AC 17 ms 3064 KB
1_00.txt AC 49 ms 14372 KB
1_01.txt AC 86 ms 14372 KB
1_02.txt AC 51 ms 14252 KB
1_03.txt AC 52 ms 14100 KB
1_04.txt AC 47 ms 14256 KB
1_05.txt AC 46 ms 14128 KB
1_06.txt AC 71 ms 14072 KB
1_07.txt AC 72 ms 13976 KB