Study Cafe
InterviewTime limit2sMemory limit1024 MB
Given seat fees and customer stay intervals, find the minimum and maximum total revenue when each day every active customer takes a distinct seat.
- Level
Medium4 of 10
- Topics
- Sorting, Prefix sum, Intervals
- Solved
- No attempts yet
Problem
Joowon runs a study cafe. The cafe has seats, and the daily fee for the -th seat is .
Joowon recently hired a new part-time worker and assigned them the job of guiding customers toward the most expensive seats possible. Joowon wants to check whether the worker is really working hard.
The cafe has usage records. Each record says that a customer used the study cafe from day to day . Every day of the stay, the customer pays the fee of one seat that the part-time worker assigned and occupies that seat for the day. A customer's seat can change from day to day.
Using the records, Joowon wants to compute the minimum and maximum revenue the cafe could have earned, so he can see how hard the worker is working. Help Joowon compute the minimum and maximum revenue.
Input
The first line contains and separated by a space.
The second line contains separated by spaces.
Each of the following lines contains and separated by a space.
Output
Print the minimum revenue and the maximum revenue separated by a space.
Constraints
- ()
- ()