Problem p01891 - Generation 3

Orig Description

A: Cabbage
Problem Statement
AOR Ika-chan has obtained a cabbage with $N$ leaves. The leaves of this cabbage are numbered from 1 to $N$ in order from the outside, and the degree of dirtiness of the $i$-th leaf is $D_i$. The larger the value, the dirtier the leaf.
AOR Ika-chan decided to select dirty leaves to be discarded according to the following procedure for using the leaves of this cabbage for cooking.
- Initialize the discard candidate to empty.
- Focus on the outermost leaf that hasn't been checked yet. If all are finished, finish.
- If the degree of dirtiness of the leaf is equal to or greater than $A$, add it to the discard candidate and return to 2. Otherwise, finish.
However, it was found that the number of leaves that could be used for cooking became extremely small as a result of this operation. Therefore, AOR Ika-chan decided to reconsider the leaves to be discarded after the above operation and to perform the following operation.
- If the number of leaves that are not discard candidates is less than $M$, proceed to 2. Otherwise, finish.
- Focus on the innermost leaf among the discard candidate leaves that has not yet been checked. If there are no discard candidate leaves, finish.
- If the degree of dirtiness of the leaf is less than or equal to $B$, remove it from the discard candidate and return to 2. Otherwise, discard all the discard candidate leaves and finish.
Find the number of leaves to be finally discarded.
Input
$N \ M \ A \ B$
$D_{1} \ D_{2} \ \cdots \ D_{N}$
Constraints
$1 \leq N \leq 1000$
$0 \leq M \leq N$
$1 \leq A \leq B \leq 1000$
$1 \leq D_{i} \leq 1000$
Output
Output the number of leaves to be finally discarded.
Sample Input 1
5 3 6 9
9 7 5 3 1
Sample Output 1
2
Discard the first and second leaves.
Sample Input 2
5 3 6 9
5 4 3 2 1
Sample Output 2
0
Do not discard any leaves from the first leaf.
Sample Input 3
5 3 6 9
10 8 6 4 2
Sample Output 3
1
Although he tried to discard the first three leaves, he changed his mind and decided not to discard the second and third leaves.
Sample Input 4
5 3 6 9
5 10 8 6 4
Sample Output 4
0
AOR Ika-chan doesn't know that the second leaf is dirty.
Sample Input 5
5 0 6 9
9 9 8 8 7
Sample Output 5
5
Do not mind discarding all of them.

Extracted Specification

An integer N (1 ≤ N ≤ 1000), representing some quantity or size.
An integer M (0 ≤ M ≤ N), representing some quantity or size.
An integer A (1 ≤ A ≤ 1000), representing some threshold value.
An integer B (A ≤ B ≤ 1000), representing some threshold value.
A list of integers D of size N, where each integer is between 1 and 1000.

### Example Input:

```
5 3 6 9
9 7 5 3 1
```

### Function Signature:
Write a function f(N, M, A, B, D) that takes in the input.
def f(N: int, M: int, A: int, B: int, D: List[int]):
    ''' 
    N: an integer 
    M: an integer
    A: an integer
    B: an integer
    D: a list of integers
    '''

Test Case Generator

Sure! Below is the test case generator for the given problem "A: Cabbage":

```python
import random

def tcgen():
    # Define the constraints
    N = random.randint(1, 1000)  # 1 <= N <= 1000
    M = random.randint(0, N)  # 0 <= M <= N
    A = random.randint(1, 1000)  # 1 <= A <= 1000
    B = random.randint(A, 1000)  # A <= B <= 1000
    D = [random.randint(1, 1000) for _ in range(N)]  # List of N elements, each 1 <= D[i] <= 1000
    
    return N, M, A, B, D

def format_tc(N, M, A, B, D):
    input_data = f"{N} {M} {A} {B}\n" + " ".join(map(str, D))
    return input_data

# Generate a test case and format it
N, M, A, B, D = tcgen()
test_case = format_tc(N, M, A, B, D)
print(test_case)
```

This generator follows the constraints provided in the problem statement. It randomly generates values for \(N\), \(M\), \(A\), \(B\), and the list \(D\) within the specified ranges. The `format_tc` function formats the output to match the expected input format of the problem.

### Explanation of the Generator
- **N**: Number of leaves.
- **M**: Minimum number of leaves that should remain for cooking.
- **A**: Threshold for initial discard based on dirtiness.
- **B**: Threshold for reconsidering the discard based on dirtiness.
- **D**: List of dirtiness values for each leaf.

### Example Output

Running the provided script might output something like:

```
623 217 195 453
234 576 123 789 456 234 876 234 345 ...
```

This output can directly be used as an input for your problem to test various scenarios.

Extract Arguments

def extract_arguments(fh):
    N, M, A, B = map(int, fh.readline().strip().split())
    D = list(map(int, fh.readline().strip().split()))
    return N, M, A, B, D