#C5946. Filter Products by Price

    ID: 49651 Type: Default 1000ms 256MiB

Filter Products by Price

Filter Products by Price

Given a catalog of products where each product is represented by its name and price, filter out the products whose price falls within a specified range. A product is considered valid if its price satisfies the condition $$min\_price \leq price \leq max\_price$$. The products should be output in the same order as they appear in the input.

Your task is to read the catalog and the price range from stdin and output the count of filtered products followed by each product on a new line (each line containing the product's name and price separated by a space) to stdout.

inputFormat

The input is read from standard input and has the following format:

  • The first line contains an integer N, the number of products.
  • The next N lines each contain a product's name (a string without spaces) and its price (an integer) separated by a space.
  • The final line contains two integers: min_price and max_price, representing the inclusive price range.

outputFormat

Output to standard output in the following format:

  • The first line should contain an integer representing the number of products whose price falls within the given range.
  • Each subsequent line should contain the product's name and price (separated by a space) for each filtered product, in the original order as they were input.
## sample
4
Laptop 1000
Smartphone 500
Tablet 300
Headphones 100
200 800
2

Smartphone 500 Tablet 300

</p>