Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #python 3.7.1
- from math import floor, ceil
- n = int(input())
- m = int(input())
- packets = list(map(int, input().split()))
- packets.sort(reverse=True)
- quality = 0
- p = 0
- a = 0
- for i in range(m-1):
- quality += packets[i]
- if packets[i] == p:
- a += 1
- else:
- p = packets[i]
- a = 1
- b = 0
- c = 0
- d = 1
- for i in range(m-1, n):
- if packets[i] == p:
- b += 1
- elif packets[i] == p-1:
- c += 1
- d += 1
- d = d/2.0
- shift = 2*(d-b)
- if a >= shift-1 and c >= shift:
- quality += p
- else:
- quality += ceil((packets[m-2+floor(d)]+packets[m-2+ceil(d)])/2.0)
- print(quality)
- '''
- 8
- 4
- 2 2 2 2 3 3 3 3
- 8
- 4
- 2 2 1 2 3 3 3 3
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement