Stuck on MAXFUN FEB21C DIV 3

#include
#include
#include <bits/stdc++.h>
using namespace std;

int main()
{
int T;
cin >> T;
cin >> ws;
for(int j = 0; j<T;j++)
{
unsigned int n;
cin >> n;
cin >> ws;
unsigned int a[n];
for(int i = 0; i<n; i++)
{
unsigned int f;
cin >> f;
cin >> ws;
a[i] = f;
}
sort(a,a + n);
cout << 2*(a[n-1]-a[0]) << endl;
}
}

This was giving correct answers with the example input but wasn’t accepted. What am i missing here?

Try only taking int a[n], instead of unsigned int a[n]. As per constraints negative values of a[i] is also possible.

2 Likes

Yes thanks! Its working now.