PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000075. Gói thuê dịch vụ theo ngày (Snuke Prime)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Gói thuê dịch vụ theo ngày (Snuke Prime)
Snuke Prime
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are services. Service is used from the beginning of day through the end of day , inclusive, and costs per day without a subscription. A subscription costing per day covers all services. Find the minimum total cost.
Input
The first line contains . Each of the next lines contains .
Output
Print the minimum total cost.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
2 6
1 2 4
2 2 4
Output
10
Explanation
On day only one service is active, costing . On day , the ordinary fees total , so the subscription for is cheaper. The answer is .