Help me in solving MAJIK problem

My issue

what i did is similar to the solution, but I have been getting a runtime error, can anyone help spot the source of error?

My code

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


int compare(const void *a, const void *b) {
    int int_a = *((int *)a);
    int int_b = *((int *)b);

    if (int_a == int_b) return 0;
    else if (int_a < int_b) return -1;
    else return 1;
}

void main(){
  long int t;
  scanf("%ld", &t);

  while(t--){
    long int n;
    scanf("%ld", &n);
    
    long int arrA[n];

    long int arrB[2];

    long int arrx[n - 2];

    long int p,q;

    scanf("%ld %ld", &p, &q);

    long int o = p+q;
    
    for (int i = 0; i < n; i++)
    {
      scanf("%ld", &arrA[i]);
    }
    
    qsort(arrA, n, sizeof(long int), compare);

    arrB[0] = arrA[0];
    arrB[1] = arrA[n - 1];

    for (int i = 0; i < n - 2; i++)
    {
      arrx[i] = abs(arrA[i + 1]);
    } 

    long int a = n - 2;

    qsort(arrx, a, sizeof(long int), compare);

    while (o > 0 && a > 0)
    {
      arrB[1] = arrB[1] + arrx[a - 1];

      o--;
      a--;
    } 

    long int difference = arrB[1] - arrB[0];

    printf("%ld\n", difference);

  }
}

Problem Link: MAJIK Problem - CodeChef