Problem #242

NiceSet

Time limit: 0.25s
Memory limit: 128MB
Input: stdin
Output: stdout

The Great Kagura loves the number S. In front of her, she has a sequence of integers \(a_1, ... , a_n\). She wants to select a collection of these integers such that the sum of the absolute values of the differences of all pairs of integers in her collection is at most S. For example, if her collection is x, y, z, then |x − y| + |x − z| + |y − z| ≤ S. She wants to select the largest collection that she can. Can you help her?

Input Data

The first line of the input contains the two integers n and S. The second line of the input contains \(a_1, ... , a_n\).

Output Data

Output the size of the largest collection of integers from among \(a_1, ... , a_n\) that satisfy the required condition.

Restrictions

  • 1 ≤ n ≤ 300 000
  • \(1 ≤ a_i ≤ 1 \ 000 \ 000 \ 000\)
  • \(1 ≤ S ≤ 10^{18}\)

Subtask 1 (6 points)

  • \(a_i = 1\)

Subtask 2 (7 points)

  • \(a_i ∈ \{1, 2\}\)

Subtask 3 (8 points)

  • \(a_i = i\)

Subtask 4 (9 points)

  • n ≤ 20
  • \(a_i ≤ 1 \ 000\)
  • S ≤ 1 000 000 000

Subtask 5 (21 points)

  • n ≤ 100
  • S ≤ 1 000 000 000

Subtask 6 (18 points)

  • n ≤ 2000
  • S ≤ 1 000 000 000

Subtask 7 (31 points)

  • No further restrictions.

Examples

stdin

5 3
1 2 3 4 5

stdout

2

Explanation

One possible collection is 1, 2. All collections with 3 elements have the sum of absolute differences at least 4.

stdin

5 4
1 2 3 4 5

stdout

3

Explanation

One possible collection is 1, 2, 3.

stdin

5 1
1 1 1 1 1

stdout

5

Explanation

The entire sequence is a valid collection.

stdin

10 7
1 5 3 2 4 3 1 3 2 100

stdout

5

Explanation

One possible collection is 2, 2, 3, 3, 3.

General info

Uploader: liviu

Author: Tamio-Vesa Nakajima

Source: infO(1) Cup 2022, Day 1

Submissions