Advertisement
DeepRest

Amazon OA: Channels & Packets

Jan 15th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #python 3.7.1
  2. from math import floor, ceil
  3. n = int(input())
  4. m = int(input())
  5. packets = list(map(int, input().split()))
  6. packets.sort(reverse=True)
  7. quality = 0
  8. p = 0
  9. a = 0
  10. for i in range(m-1):
  11.   quality += packets[i]
  12.   if packets[i] == p:
  13.     a += 1
  14.   else:
  15.     p = packets[i]
  16.     a = 1
  17. b = 0
  18. c = 0
  19. d = 1
  20. for i in range(m-1, n):
  21.   if packets[i] == p:
  22.     b += 1
  23.   elif packets[i] == p-1:
  24.     c += 1
  25.   d += 1
  26. d = d/2.0
  27. shift = 2*(d-b)
  28. if a >= shift-1 and c >= shift:
  29.   quality += p
  30. else:
  31.   quality += ceil((packets[m-2+floor(d)]+packets[m-2+ceil(d)])/2.0)
  32. print(quality)
  33.  
  34. '''
  35. 8
  36. 4
  37. 2 2 2 2 3 3 3 3
  38.  
  39. 8
  40. 4
  41. 2 2 1 2 3 3 3 3
  42. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement