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.## The function is expected to return a LONG_INTEGER.# The function accepts following parameters:# 1. LONG_INTEGER_ARRAY p# 2. LONG_INTEGER_ARRAY x# 3. LONG_INTEGER_ARRAY y# 4. LONG_INTEGER_ARRAY r#defmaximumPeople(p,x,y,r):townsCount=len(x)cloudsCount=len(y)townPopulation=ptownLocations=xcloudLocations=ycloudRanges=rsunnyPeople=0# get every cloud effective rangeclouds=[]foriinrange(cloudsCount):x=[cloudLocations[i]]forjinrange(cloudRanges[i]):x.append(cloudLocations[i]-1)x.append(cloudLocations[i]+1)clouds.append(x)# get towns exposed to sun and append its population to sunnyPeople# and clouded towns population to cloudedclouded=[]fortownLocationintownLocations:forindex,sublistinenumerate(clouds):iftownLocationinsublist:clouded.append(townPopulation[townLocations.index(townLocation)])else:sunnyPeople+=townPopulation[townLocations.index(townLocation)]# return sunnyPeople and the max population exposed to sunreturnsunnyPeople+max(clouded)if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')n=int(input().strip())p=list(map(int,input().rstrip().split()))x=list(map(int,input().rstrip().split()))m=int(input().strip())y=list(map(int,input().rstrip().split()))r=list(map(int,input().rstrip().split()))result=maximumPeople(p,x,y,r)fptr.write(str(result)+'\n')fptr.close()
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 →