Runtime error on IDE: BFRIEND

I tried doing this using long long int but it was unable to finish running even on my local Codeblocks IDE, could anyone point out where I went wrong?

CODE HERE:-

#include<stdio.h>
int main(){
    long int n, i, t;
    long int a, b, c;
    scanf("%d", &t);
    while(t){
        long int min=1e18+3;
        scanf("%ld", &n);
        scanf("%ld", &a);
        scanf("%ld", &b);
        scanf("%ld", &c);
        long int f[n];
        for(i=0; i<n; i++){
            scanf("%ld", &f[i]);
        }
        for(i=0; i<n; i++){
            if(f[i]<min){
                min=f[i];
            }
        }
        long int time = abs(abs(min-b)+c+abs(min-a));
        printf("%ld\n", time);
        t--;
    }
    return 0;
}

—END CODE—

1 Like

U used long int for min and value assigned to it is 10 power 18 ,that value won’t fit in int so u should change it to long long .

2 Likes

https://www.codechef.com/viewsolution/29186915
logical mistake you made,
it’s not needed that the number is minimum what matters is the total output should be minimum, and this is how to solve that.

1 Like

yeah, that and also I used abs twice here

that meant it was reducing value from 2999999997 to 1294967299
idk why the reduction was so severe tho

1 Like

make min value 10^13 and logic u had did may be wrong because there might be a case where we can get min ans other than min u have calculated