is there any other way to avoid TLE or simplify the given code?

i did the below code:

int n, q, l, r;
    scanf("%d %d", &n, &q);
    int a[n], i, j, sum;
        scanf("%d", &a[i]);
        scanf("%d %d", &l, &r);
        printf("%d\n", sum);

here n is to take the size of the array and q is the number of test cases. l & r are respectively lower and upper index limit. the goal is to take l & r for each test cases and print the summations of array elements from a[l] to a[r]. is there any other way to simplify the code to avoid TLE?

Read more here:

Content Attribution

This content was originally published by Sanzida Hossain at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: