#QHD0000019. Định giá vé máy bay (Plane Ticket Pricing)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Định giá vé máy bay (Plane Ticket Pricing)
Plane Ticket Pricing
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
An airline has unsold seats for a flight departing in weeks. It may set a ticket price each week and wants to maximize revenue by departure.
Each of the pricing decisions offers several prices with associated demand. Choosing price with demand sells tickets if seats remain, and unsold seats carry over to the following week.
Find the maximum total revenue. Among all optimal strategies, report the smallest possible price at the first pricing decision.
Input
The first line contains and .
The next blocks describe weeks down to . Each block starts with , the number of price options, followed by a line of increasing prices and a line of corresponding demands .
Output
Print the maximum revenue on the first line.
Print the smallest optimal first-week price on the second line.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; There are pricing decisions and each week’s prices are increasing.
- Subtask 2 (30 points): ; ; ; ; ; There are pricing decisions and each week’s prices are increasing.
- Subtask 3 (50 points): ; ; ; ; ; There are pricing decisions and each week’s prices are increasing.
Examples
Input
50 2
1 437 47
3 357 803 830 13 45 46
1 611 14
Output
23029
437
Explanation
There are seats and three pricing decisions because . The first week offers price with demand . Later prices depend on the remaining seats. The first week sells seats at , earning , with seats remaining. In the next week all can be sold at , earning another . Total revenue is , and the first-week price is . The output contains these values on separate lines.