PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000127. Valera hái trái cây (Valera and Fruits)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Valera hái trái cây (Valera and Fruits)
Valera and Fruits
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Fruit tree produces fruits that ripen on day . These fruits may only be harvested on days and . At most fruits can be harvested per day. Maximize the total collected.
Input
The first line contains . The next lines contain .
Output
Print the maximum number of fruits harvested.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
2 3
1 5
2 3
Output
8
Explanation
Harvest three fruits on day ; two old fruits and one new fruit on day ; then two remaining fruits on day . Total .