Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''from functools import reduce
- import operator
- n,k=map(int,input().split())
- a= list([int(s) for s in input().split()])
- print(reduce(lambda x,y: x+1 if (y>=a[k] and y>0),a))
- '''
- def sorted_histogram(a,b):
- c=list(zip(a,b))
- c=sorted(c,key=lambda x: x[0])
- a,b=zip(*c)
- d=dict()
- a=list(a)
- b=list(b)
- z=[b[0]]
- for i in range(len(a)-1):
- if a[i]==a[i+1]:
- z.append(b[i+1])
- i+=1
- else:
- d[a[i]]=z
- i+=1
- z=[b[i]]
- d[a[-1]]=z
- return d
- n=int(input())
- a=[int(s) for s in input().split()]
- b=[int(s) for s in input().split()]
- d=sorted_histogram(a,b)
- #print(d)
- ff=0
- e={}
- x=0
- while x!=1:
- #print(d.keys())
- for i in d.keys():
- if len(d[i])!=1:
- e[i+1]=[]
- while len(d[i])!=1:
- e[i+1].extend([min(d[i])])
- d[i].remove(min(d[i]))
- #print(e)
- for i in e.keys():
- while e[i]!=[]:
- if i not in d.keys():
- d[i]=[]
- d[i].extend(e[i])
- ff+=sum(e[i])
- e[i]=[]
- x=1
- for i in d.keys():
- if len(d[i])!=1:
- x=0
- #print(d)
- print(ff)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement