#GD0000109. Hộp kẹo – phiên bản khó (Candy Box (Hard Version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hộp kẹo – phiên bản khó (Candy Box (Hard Version))
Candy Box (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You have candies; candy has type and preference flag , where means willing to give it away. Choose a gift such that the positive counts of selected candies of different types are pairwise distinct. First maximize the total selected count; among maximum-size gifts maximize the number with flag . Print both numbers.
Input
Line 1 contains . Each of the next lines contains .
Output
Print two integers: the maximum number of gifted candies and the maximum number with flag among gifts of that size.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5
1 1
1 0
2 1
2 1
3 0
Output
3 3
Explanation
There are two candies each of types and one of type . Choose both type- candies and the preferred type- candy, giving distinct positive type counts and and three flagged- candies. Output 3 3.