Seats
Time limit2sMemory limit512 MB
Choose K of N passengers to sit in a row of L seats, maximizing the sum of A_i plus B_i per adjacent empty seat, for every K from 1 to N.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Divide and conquer, Sorting
- Solved
- No attempts yet
Problem
The subway in town X is a bit unusual. A train has a single wagon with one row of seats. The wagon holds passengers, numbered from to . Each passenger gets pleasure as follows:
- If a passenger is standing, the pleasure is .
- If a passenger is sitting, the passenger gets pleasure from sitting, plus pleasure for each empty seat between the passenger and a neighboring passenger or the end of the row.
For example, let there be 3 passengers with , , , , , , and let . Consider this seating, where _ is an empty seat:
_ 0 _ _ 1 _
Passenger 2 is standing.
- Passenger 0 gets for sitting and for the empty seats (1 on the left and 2 on the right), for a total of .
- Passenger 1 gets for sitting and for the empty seats (2 on the left and 1 on the right), for a total of .
- Passenger 2 gets because the passenger is standing.
The total pleasure of all passengers is .
Write a program that, given , , and the characteristics of each passenger, finds the maximum possible total pleasure for every number of seated passengers from to .
Input
The first line contains two integers and , the number of passengers and the number of seats. Each of the next lines contains two non-negative integers and for passenger .
Output
Print lines. The -th line contains the maximum total pleasure the passengers can get when exactly of them are sitting. For , print , because no valid configuration of passengers fits in seats.