#P1094. New Year Souvenir Grouping

    ID: 12988 Type: Default 1000ms 256MiB

New Year Souvenir Grouping

New Year Souvenir Grouping

With the New Year approaching, the student council has entrusted Lele with the task of distributing souvenirs at the New Year's celebration. To ensure that each participant receives souvenirs of roughly equal total value, the souvenirs must be grouped by their prices. However, each group may contain at most two items, and the sum of the prices in any group must not exceed a given integer k. In order to complete the distribution as quickly as possible, Lele wants to minimize the total number of groups formed.

Problem Constraints:

  • Each group can include at most two souvenirs.
  • The total price in any group is at most k (i.e. \(a + b \le k\)).
  • Minimize the number of groups used.

inputFormat

The first line contains two space-separated integers n and k, where n denotes the number of souvenirs, and k denotes the maximum allowed sum of prices in a group.

The second line contains n space-separated integers representing the price of each souvenir.

outputFormat

Output a single integer representing the minimum number of groups required to distribute all the souvenirs under the given conditions.

sample

4 10
7 2 3 9
3