#C10503. Warehouse Product Management
Warehouse Product Management
Warehouse Product Management
You are given a list of products in a warehouse. Each product is described by three attributes: a product ID, its weight, and its expiration date. Your task is to process the list of products and output the following information:
- The ID(s) of the heaviest product(s). Formally, if a product has weight \(w\), you need to report any product whose weight is \(\max\{w_i\}\).
- The ID(s) of the product(s) that will expire the soonest. In other words, among all expiration dates in the format \(YYYY-MM-DD\), find the minimum date.
- The IDs of all products sorted by weight in descending order.
- The IDs of all products sorted by expiration date in ascending order.
The input is read from standard input and the results are written to standard output. Each list of IDs should be printed as a space separated string on its own line in the order specified above.
inputFormat
The first line contains an integer \(n\) representing the number of products. The following \(n\) lines each contain a product record with three fields separated by spaces:
- Product ID (a string)
- Weight (a positive integer, represented as a string)
- Expiration date in the format
YYYY-MM-DD
outputFormat
Print four lines:
- The IDs of the heaviest product(s) separated by a space.
- The IDs of the product(s) with the earliest expiration date separated by a space.
- All product IDs sorted by weight in descending order separated by a space.
- All product IDs sorted by expiration date in ascending order separated by a space.
5
P001 2000 2023-12-01
P002 1500 2023-11-15
P003 2000 2023-11-20
P004 1800 2023-11-25
P005 1600 2023-11-15
P001 P003
P002 P005
P001 P003 P004 P005 P002
P002 P005 P003 P004 P001
</p>