#K6746. Minimum Employees

    ID: 32647 Type: Default 1000ms 256MiB

Minimum Employees

Minimum Employees

You are given a list of tasks, where each task is represented by a positive integer indicating its workload, and an integer k which represents the maximum workload an employee can handle. Your goal is to determine the minimum number of employees required so that the sum of the workloads assigned to any employee does not exceed k. This problem can be modeled as a bin packing problem, where each employee is a bin of capacity \(k\) and each task is an item with a given size.

Note: The tasks can be assigned in any order, and an employee can handle multiple tasks as long as the total workload does not exceed the capacity \(k\).

Examples:

  • For tasks [4, 8, 6, 1, 2, 3] with \(k = 10\), the minimum number of employees required is 3.
  • For tasks [5] with \(k = 5\), the answer is 1.
  • For tasks [2, 2, 2, 2, 2] with \(k = 5\), the answer is 3.

The solution may require using a backtracking or DFS (depth-first search) approach to explore different task assignments optimally.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains two integers n and k, where n is the number of tasks, and k is the maximum workload capacity per employee.
  2. The second line contains n space-separated positive integers representing the workload of each task.

outputFormat

Output a single integer representing the minimum number of employees required. The output should be written to standard output (stdout).

## sample
6 10
4 8 6 1 2 3
3