• + 1 comment
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    #
    # 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
    #
    
    def maximumPeople(p, x, y, r):
        townsCount = len(x)
        cloudsCount = len(y)
        
        townPopulation = p
        townLocations = x
        cloudLocations = y
        cloudRanges = r
        
        sunnyPeople = 0
        
        # get every cloud effective range
        clouds = []
        for i in range(cloudsCount):
            x = [cloudLocations[i]]
            for j in range(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 clouded
        clouded = []
        for townLocation in townLocations:
            for index, sublist in enumerate(clouds):
                if townLocation in sublist:
                    clouded.append(townPopulation[townLocations.index(townLocation)])
                else:
                    sunnyPeople += townPopulation[townLocations.index(townLocation)]
        
        # return sunnyPeople and the max population exposed to sun
        return sunnyPeople + 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()