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?


int main(){
    long int n, i, t;
    long int a, b, c;
    scanf("%d", &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++){
        long int time = abs(abs(min-b)+c+abs(min-a));
        printf("%ld\n", time);
    return 0;


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 .

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