The puzzle consists from something like this:You will receive an array of integer with values, then you will receive X numbers. Each number (call it x) represents an index of a 1-indexed array. Look up the value in the array (call it y), then subtract 1 from all the values in the array in the range [x-y, x+y]. The minimum value is 0.After the given number of operations, you must return the sum of all values in the array.My code looks like this.#include <cstdio>int array[111111];int main(){  int m,n;  unsigned long long int sum = 0;  //here n is the size of the array, and m is the number of operations  scanf(%d %d, &n, &m);  for (int i = 0; i < n; i++){    scanf(%d, &array[i]);    sum+= array[i];  }  for (int i = 0; i < m; i++) {    int idx;    scanf(%d, &idx);    int count= array[idx - 1];    for (int j = (idx -1 -count >=0 ? idx -1 -count : 0); j < (idx + count <=n ? idx + count : n); j++)      if (array[j]){        sum--;        array[j]--;      }  }  printf(%d\n, sum);}It solves the problem, but does not pass in the worst case, that would be a ton of cases decreasing from the entire array, basically an O(n*n) (I think).The value restrictions are:1  N,M  100000;Value inside array index between 0 and 50000.Test case:Input:10 41 2 0 8 4 2 9 8 1 39 5 10 6Output:23Visualization of the test case:For example, the first number that is read is 9. If we treat the number sequence as a 1-indexed array, we read value 1. This means that we need to subtract 1 from every value in the range [9-1, 9+1], which corresponds to the last three elements of the array.
Calculating sum after ranged-based subtractions
c++;algorithm;array;time limit exceeded