Help me in solving PREFPRO2 problem

My issue

not runing

My code

#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;
    scanf("%d", &n);

    int *arr = (int *)malloc(n * sizeof(int));
    if (arr == NULL) {
        printf("Memory allocation failed\n");
        return 1;
    }

    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    int *prefix = (int *)malloc(n * sizeof(int));
    if (prefix == NULL) {
        printf("Memory allocation failed\n");
        free(arr);
        return 1;
    }

    prefix[0] = arr[0];
    for (int i = 1; i < n; i++) {
        prefix[i] = prefix[i - 1] + arr[i];
    }

    int k;
    scanf("%d", &k);

    for (int i = 0; i < k; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        int sum;
        if (a == 1) {
            sum = prefix[b - 1];
        } else {
            sum = prefix[b - 1] - prefix[a - 2];
        }

        printf("%d\n", sum);
    }

    free(arr);
    free(prefix);
    return 0;
}

Learning course: Prefix sums
Problem Link: Optimization Using Prefix Array Practice Problem in Prefix sums - CodeChef

Your ints are overflowing.

Note how you can have an array of 10^5 elements, possibly with a value of 10^5 each.
Then, the prefix sum can be 10^10, and integers can only store numbers up to 10^9 moreless.

Use long long for your prefix array.