Help me debug my code

Solution: 48622960 | CodeChef : my code.
Please tell me why is this wrong and how can I correct it.

You needed to check till 100 , whereas you are checking till only 99.

Some ques.

What error are you getting?
What exactly is the purpose of checkarr…it seems to be doing nothing.
you can just count the arr2 values directly.

You are using 0-based indexing for arr2, but the valuep and valuen are 1-based. You need to subtract 1 from both these values initially.

1 Like
{
    int m , x , y , valuep = 0 , valuen = 0, count = 0;
    int arr2[101];
    for(int i = 0;i<101;i++){
        arr2[i]=0;
    }
    
    cin>>m>>x>>y;
    int arr[m];
    
    for(int k = 0; k < m ; k++)
    {
        cin>>arr[k];
    }
    
    int z = x * y ;
    
    for(int i = 0 ; i < m ; i++)
    {
        valuep = z + arr[i];//41
        valuen = arr[i] - z;//1
        
        if(valuen<=0)
        {
            valuen = 1;
        }
        if(valuep>100)
        {
            valuep = 100;
        }
        
        for(int j = valuen ; j <= valuep ; j++)
        {
            arr2[j]=1;
        }
        
    }
    
    for(int d = 0 ; d <= 100 ; d++)
    {
            if(arr2[d]==1)
            {
                count++;
            }
    }
    
    cout<<100-count<<'\n';
}

//just gothrough these code you will understand by yourselves