Big Buckets
You have a list of n numbers, labelled i1 to in, that you're trying to put inside different buckets.
Each bucket can hold any amounts of numbers in it. However, for each bucket, strictly more than half of its content must be identical.
What is the minimum number of buckets needed to pack all n numbers?
Input
Your first line will contain the integer n.
Your next n lines will contain one integer each, which are the numbers waiting to be put inside buckets.
Output
One line, containing the minimum number of buckets needed to pack all n numbers.
Constraints
- 1≤n≤106
- 1≤i1...in≤106
Python Template
n = map(int, input.split())
numbers = [int(input()) for _ in range(n)]Example 1
5
4
7
4
3
2
3
Explanation
In this scenario, the n=5 numbers can be put inside 3 buckets. One possible combination would be [2], [3], [4, 4, 7]. Each bucket has strictly more than half of the elements identical to each other.
Example 2
8
3
5
12
3
3
5
3
4
2
Explanation
In this scenario, the n=8 numbers can be put inside 2 buckets. One possible combination would be [3, 3, 3, 4, 12], [3, 5, 5].
Example 3
9
6
23
6
6
6
6
6
6
6
1
Explanation
In this scenario, all n=9 numbers can be put inside the same bucket.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.