#C3960. Minimum Robots Needed

    ID: 47445 Type: Default 1000ms 256MiB

Minimum Robots Needed

Minimum Robots Needed

You are given a set of N items with specified weights and a robot's weight capacity W. Each robot can carry at most two items at the same time provided the sum of their weights does not exceed W. The task is to determine the minimum number of robots needed to carry all the items.

You may pair items in an optimal manner, and if an item cannot be paired with any other without exceeding the weight limit, it will require its own robot. The decision of pairing should be made in such a way that minimizes the total number of robots used.

Formally, given an integer N, an integer W (the maximum weight capacity for each robot), and a list of integers representing the weights of the items, find the smallest number of robots required such that each robot carries at most two items and the sum of the weights of items carried by a robot is at most W.

The pairing condition can be described using the following inequality in LaTeX format:

wi+wjWw_i + w_j \leq W

where \(w_i\) and \(w_j\) are the weights of the paired items.

inputFormat

The input consists of two lines:

  1. The first line contains two integers N and W separated by a space, where N is the number of items and W is the maximum weight a robot can carry.
  2. The second line contains N integers separated by spaces, representing the weights of the items.

outputFormat

Output a single integer on a new line representing the minimum number of robots required.

## sample
3 10
4 8 6
2

</p>