#BS0000120. Chọn hoa (Choosing Flowers)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chọn hoa (Choosing Flowers)
Choosing Flowers
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Vladimir must choose exactly flowers among types, each available in unlimited quantities. The first flower of type brings happiness, and each additional flower of the same type brings . Choosing flowers of type contributes ; choosing none contributes . The sum of all chosen quantities must be exactly . Find the maximum total happiness.
Input
The first line contains . Each of the next lines contains two integers describing flower type (-based).
Output
Print one integer: the maximum happiness attainable using exactly flowers.
Subtasks
- Subtask 1 (20 points): ; ; for all .
- Subtask 2 (30 points): ; ; for all .
- Subtask 3 (50 points): ; ; for all .
Examples
Input
4 3
5 0
1 4
2 2
Output
14
Explanation
We need flowers. One flower of type yields . Three flowers of type yield . Together they yield . No allocation of exactly four flowers yields more, so the answer is 14.