#K75092. Maximum Trips for Treasure Transport

    ID: 34342 Type: Default 1000ms 256MiB

Maximum Trips for Treasure Transport

Maximum Trips for Treasure Transport

You are given n islands where treasures are located, an array of weights representing the weight of the treasure on each island, and a shipping container with capacity C. In each trip, you can transport either one or two treasures. Two treasures can be transported together in a single trip if and only if their combined weight does not exceed \(C\).

Your task is to compute the maximum number of trips required to transport all the treasures. In other words, if the weights are \(w_1, w_2, \dots, w_n\), you need to find the maximum number of trips such that in each trip you can take either a single treasure or a pair \(w_i\) and \(w_j\) satisfying \(w_i + w_j \leq C\).

inputFormat

The input is provided via standard input (stdin) and consists of two lines:

  1. The first line contains two integers n and C separated by a space, where n is the number of islands and C is the container capacity.
  2. The second line contains n space-separated integers representing the weights of the treasures.

outputFormat

Output a single integer to standard output (stdout), representing the maximum number of trips required to transport all the treasures.

## sample
5 50
10 20 30 40 50
3

</p>