PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000071. Hàng đợi ngân hàng (Bank Queue)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hàng đợi ngân hàng (Bank Queue)
Bank Queue
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
The bank remains open for minutes, with service slots numbered through . Customer wants to deposit units and must start service by minute or leave. Serving a customer takes exactly one minute, and each slot serves at most one customer. Maximize the total deposited money.
Input
The first line contains . Each of the next lines contains .
Output
Print the maximum total cash.
Subtasks
- Subtask 1 (20 points): ; ; , for every .
- Subtask 2 (30 points): ; ; , for every .
- Subtask 3 (50 points): ; ; , for every .
Examples
Input
5 3
100 0
50 1
120 0
100 2
35 2
Output
270
Explanation
Serve the customer at minute , the customer at minute , and the customer with deadline at minute . The total is . Only one of the two customers whose deadline is can be served.