Company: Salesforce
Difficulty: medium
A Salesforce administrator is managing resource allocation across n regions for a marketing campaign. These regions are represented by an array arr of length n , where initially, each element of the array is set to 0. The administrator needs to perform q updates on the array arr , following these rules: An update is specified as i x , where: i is the index of the primary region to which x units of resources are allocated. Neighboring regions also receive a portion of the resources, with the allocated units decreasing as the distance from i increases. Specifically, for each region j , the resources are updated as: arr[j] = arr[j] + x - |j - i| This applies to all regions j such that: |j - i| < x 0 ≤ j < n After all q updates are applied, output the final resource allocation across all regions. For example, n = 5 , q = 3 , query = [(2, 2), (1, 3), (4,1)] Initially, arr = [0, 0, 0, 0, 0] qry 0 = 2 2 - Add 2 to index 2, add 1 to indices 1 and 3. arr = [0, 1, 2, 1, 0] qry 1 = 1 3 - Ad