PUBG Lover Programmer: The Beginning

Sroud loves to play PUBG and does programming contest. He always thinks about converting gameplay to programming, and most of the times he gets weird idea. The problem mentioned below is the output of one of those weird ideas.


This is a companion discussion topic for the original entry at https://toph.co/p/pubg-lover-programmer-the-beginning
#include<stdio.h>
int main()
{
    int n,x,arr[120],sum=0,res;
    scanf("%d %d",&n,&x);
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        sum+=arr[i];
        res=sum-x;
    }

    printf("%d\n",res);
}

why i got runtime error

1 Like

@Dibbendu.040619 The input specification of this problem was not formatted correctly (e.g. 10^5 was being shown as 105). The statement has been updated.

Please try solving the problem again with the correctly formatted problem statement.

Sorry for the inconvenience.

#include<stdio.h>
int main()
{

    long int n,x,sum=0,res,arr[100000];
    scanf("%d %d",&n,&x);

    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        sum+=arr[i];
        res=sum-x;
    }

    printf("%d\n",res);
}

why i got error on test case 2