• + 1 comment

    You don't even have to store the array, you can do the counting inline while reading the input:

    int apples = 0;
    
    for(int i=0; i < m; ++i){
        long d = in.nextLong();
        long p = d+a;
        if ( p >= s && p <= t ) ++apples;
    }