We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importmathimportosimportrandomimportreimportsys# Complete the maximumPeople function below.fromcollectionsimportdefaultdictdefmaximumPeople(towns,cloud_start,cloud_end):towns=sorted(towns)cloud_start=sorted(cloud_start)cloud_end=sorted(cloud_end)cloud_start_i=0cloud_end_i=0clouds=set()d=defaultdict(int)free=0fortown_iinrange(len(towns)):town_x=towns[town_i][0]whilecloud_start_i<len(cloud_start)andcloud_start[cloud_start_i][0]<=town_x:clouds.add(cloud_start[cloud_start_i][1])cloud_start_i+=1whilecloud_end_i<len(cloud_end)andcloud_end[cloud_end_i][0]<town_x:clouds.remove(cloud_end[cloud_end_i][1])cloud_end_i+=1iflen(clouds)==1:towns[town_i][2]=list(clouds)[0]d[list(clouds)[0]]+=towns[town_i][1]eliflen(clouds)==0:free+=towns[town_i][1]returnmax(d.values(),default=0)+freedefmain():n=int(input().strip())p=[int(x)forxininput().strip().split()]x=[int(x)forxininput().strip().split()]towns=[[xi,pi,-1]forxi,piinzip(x,p)]m=int(input().strip())y=[int(x)forxininput().strip().split()]r=[int(x)forxininput().strip().split()]cloud_start=[[y[i]-r[i],i]foriinrange(m)]cloud_end=[[y[i]+r[i],i]foriinrange(m)]result=maximumPeople(towns,cloud_start,cloud_end)print(result)if__name__=="__main__":main()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cloudy Day
You are viewing a single comment's thread. Return to all comments →