In a codechef problem Maximise Function
My code for the problem is:
#include<iostream> #include<math.h> using namespace std; void swap(long long int *x, long long int *y) { long long int temp = *x; *x = *y; *y = temp; } void BubbleSort(long long int n, long long int a[]) { // long long int i, j; for(long long int i=0; i<n-1; i++) { for(long long int j=0; j<n-i-1; j++) { if(a[j]>a[j+1]) { swap(a[j], a[j+1]); } } } } int main() { long long int k; cin>>k; while(k--) { long long int n; long long int a[n]; cin>>n; for(long long int i=0; i<n; i++) { cin>>a[i]; } BubbleSort(n ,a); cout<<2*abs((a[n-1]-a[0]))<<"\n"; } return 0; }
The code is running fine with CodeChef IDE when using int as a data type for all the variables below, but when the datatype is changed to long long int (because of the given constraints), the CodeChef IDE is giving a runtime error. I am unable to understand the problem that is occurring. Please help me to spot that problem.
Runtime Error: SIGEMT