Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. '''from functools import reduce
  2. import operator
  3. n,k=map(int,input().split())
  4. a= list([int(s) for s in input().split()])
  5. print(reduce(lambda x,y: x+1 if (y>=a[k] and y>0),a))
  6. '''
  7.  
  8. def sorted_histogram(a,b):
  9. c=list(zip(a,b))
  10. c=sorted(c,key=lambda x: x[0])
  11. a,b=zip(*c)
  12. d=dict()
  13. a=list(a)
  14. b=list(b)
  15. z=[b[0]]
  16. for i in range(len(a)-1):
  17. if a[i]==a[i+1]:
  18. z.append(b[i+1])
  19. i+=1
  20. else:
  21. d[a[i]]=z
  22. i+=1
  23. z=[b[i]]
  24. d[a[-1]]=z
  25. return d
  26.  
  27.  
  28.  
  29.  
  30. n=int(input())
  31. a=[int(s) for s in input().split()]
  32. b=[int(s) for s in input().split()]
  33. d=sorted_histogram(a,b)
  34. #print(d)
  35. ff=0
  36. e={}
  37. x=0
  38. while x!=1:
  39. #print(d.keys())
  40. for i in d.keys():
  41. if len(d[i])!=1:
  42. e[i+1]=[]
  43. while len(d[i])!=1:
  44. e[i+1].extend([min(d[i])])
  45. d[i].remove(min(d[i]))
  46.  
  47. #print(e)
  48. for i in e.keys():
  49. while e[i]!=[]:
  50. if i not in d.keys():
  51. d[i]=[]
  52. d[i].extend(e[i])
  53. ff+=sum(e[i])
  54. e[i]=[]
  55. x=1
  56. for i in d.keys():
  57. if len(d[i])!=1:
  58. x=0
  59.  
  60. #print(d)
  61. print(ff)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement