PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000103. Thưởng thức sushi đa dạng (Various Sushi)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Thưởng thức sushi đa dạng (Various Sushi)
Various Sushi
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are sushi pieces. Piece has type and deliciousness . Choose exactly distinct pieces. If different types are present, your satisfaction is the sum of deliciousness values plus . Maximize satisfaction.
Input
Line 1 contains . Each of the next lines contains .
Output
Print one integer, the maximum possible satisfaction.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
5 3
1 9
1 7
2 6
2 5
3 1
Output
26
Explanation
Choose pieces with deliciousness . Their base sum is , and two distinct types contribute , giving .