"WA" when int, "AC" when long long int

hello everyone, while solving this question , I took an array arr[n] of int because the numbers lie in range of 10^-5 and 10^5…I think the numbers can easily fit in int…but it gives me WA … but when i change it to long long int , it gives me AC…why so??

My submission : Submission #19424524 - AtCoder Beginner Contest 180
Problem Link : B - Various distances

Code :

void solve()
long long int n;

**int arr[n];**// when i change it to long long int, it gives me AC, but why? since the constraints are not big, it should have worked fine with int also

for(lli i=0;i<n;i++)
long long int m=0;
long long int e=0;
int  c=0;
for(lli i=0;i<n;i++)
{   m+=abs(arr[i]);
 double E=(double)(pow(e,0.5));


Euclidean distance takes square of every coordinate. If you square 10^5, it will result in overflow.

1 Like

but i have store the sqaured value in long long int e

try this

int a = 1e8;
long long int val = a*a;

What you are seeing is called type casting. Product of two ints is also stored in int. You need to explicitly cast them to long long. Like this

long long e = (long long) a * b;

Here we are casting a to long long explicitly and b will get cased to long long implicitly. Then the product will be stored in e.

1 Like

i got it…thanks a lot