-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path456.py
More file actions
49 lines (45 loc) · 937 Bytes
/
456.py
File metadata and controls
49 lines (45 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
n,m,e = map(int,input().split())
data = [0 for _ in range(100)]
temp = list(map(int,input().split()))
first = temp[0]
end = temp[len(temp)-1]
for i in temp:
data[i] = 1
result = 0
if e <= first:
cnt = 0
i = 0
while cnt != m:
cnt += data[i]
i += 1
result = i - e - 1
elif e >= end:
cnt = 0
i = e
while cnt != m:
cnt += data[i]
i -= 1
result = i
next = first
cnt = 0
start = first
partend = next
result = 987654321
while partend < end:
cnt = 0
start = partend
while cnt != m:
cnt += data[next]
next += 1
partend = next - 1
next = partend
if start <= e and partend >= e:
if result > partend - start:
result = partend - start
elif start < e:
if result > e - start:
result = e - start
elif partend > e:
if result > partend - e:
result = partend - e
print(result)