• + 0 comments
    void countApplesAndOranges(int s, int t, int a, int b, vector<int> apples, vector<int> oranges) {
        // get the coordinates of the fallen fruits and check whether they are in [s, t]
        std::transform(apples.begin(), apples.end(), apples.begin(),
        [a,s,t] (int d) {
            return (a + d >= s && a + d <= t) ? 1 : 0;     
        });
        std::transform(oranges.begin(), oranges.end(), oranges.begin(),
        [b,s,t] (int d) {
           return (b + d >= s && b + d <= t) ? 1 : 0; 
        });
        
        // then just sum up the elements and print the result
        std::cout << std::accumulate(apples.begin(), apples.end(), 0) << std::endl;
        std::cout << std::accumulate(oranges.begin(), oranges.end(), 0) << std::endl;
    }