#C7695. Filtering Completed Items by Time Frame

    ID: 51594 Type: Default 1000ms 256MiB

Filtering Completed Items by Time Frame

Filtering Completed Items by Time Frame

You are given two lists: one containing milestones and another containing features. Each entry in both lists consists of a name and a completion date in the format \(YYYY\text{-}MM\text{-}DD\). You are also provided with a set of queries. Each query specifies a start date and an end date that form an inclusive time frame.

For every query, your task is to determine which milestones and features were completed within the specified time frame. You should output the names of the milestones (in the order given) followed by the names of the features (again, in the given order) that have completion dates within the query range.

Note that the dates follow the ISO 8601 format so that lexicographical string comparison is valid for comparing dates.

inputFormat

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

  • The first line contains two integers \(M\) and \(F\) — the number of milestones and the number of features respectively.
  • The next \(M\) lines each contain a milestone name and its completion date, separated by a space.
  • The following \(F\) lines each contain a feature name and its completion date, separated by a space.
  • The next line contains an integer \(Q\) — the number of queries.
  • The following \(Q\) lines each contain two dates: the start date and the end date of the query.

outputFormat

Output a single line on standard output (stdout) containing the names of all items that were completed within the given queries. For each query, first output the milestone names (in their input order) that fall within the query time frame, followed by the feature names (in their input order) that also fall within the time frame. Separate the names by a single space. If no item falls within the given time frame(s), output an empty line.

## sample
3 5
Milestone1 2023-01-20
Milestone2 2023-01-25
Milestone3 2023-02-01
Feature1 2023-01-15
Feature2 2023-01-22
Feature3 2023-01-25
Feature4 2023-02-02
Feature5 2023-02-10
1
2023-01-10 2023-01-25
Milestone1 Milestone2 Feature1 Feature2 Feature3