#K38397. Minimum Late Packages

    ID: 26189 Type: Default 1000ms 256MiB

Minimum Late Packages

Minimum Late Packages

You are given n packages, each with a deadline by which it must be delivered. Additionally, there are m available drones that can deliver these packages. Each drone can deliver only one package at a time, and only the first m packages (after ordering) have a chance to be delivered on time if their deadlines allow. For packages in positions i < m (where i is 0-indexed), if the deadline is strictly greater than i, then the package is delivered on time; otherwise, it is considered late. All packages with index i ≥ m are automatically regarded as late because no drone is available immediately.

Your task is to compute the minimum number of packages that will be delivered past their deadline.

Note: The input deadlines must be sorted in ascending order before considering the above rule.

Mathematically, given a sorted array of deadlines \(d_0, d_1, \dots, d_{n-1}\) and an integer \(m\), the number of late packages is given by:

[ \text{late} = \left(n - \sum_{i=0}^{\min(m, n)-1} \mathbb{1}_{{d_i > i}}\right), ]

where \(\mathbb{1}_{\{condition\}}\) is 1 if the condition is true and 0 otherwise.

inputFormat

The first line of input contains two integers n and m separated by a space, where n is the number of packages and m is the number of drones available. The second line contains n space-separated integers, representing the deadlines for each package.

outputFormat

Output a single integer indicating the minimum number of packages that will be delivered late.

## sample
5 3
1 2 3 4 5
2