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 another quantity or threshold.
An integer A (1 ≤ A ≤ 1000), representing a threshold.
An integer B (1 ≤ B ≤ 1000), representing another threshold.
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.
```python
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, here is a test case generator for the given competitive programming problem "A: Cabbage":
```python
import random
def tcgen():
N = random.randint(1, 1000)
M = random.randint(0, N)
A = random.randint(1, 1000)
B = random.randint(A, 1000) # Ensure B is at least A
D = [random.randint(1, 1000) for _ in range(N)]
return N, M, A, B, D
# Example usage:
for _ in range(5): # Generate 5 test cases
N, M, A, B, D = tcgen()
print(f"{N} {M} {A} {B}")
print(" ".join(map(str, D)))
```
### Explanation:
1. **N**: Number of leaves, randomly generated between 1 and 1000.
2. **M**: Minimum number of leaves required for cooking, randomly generated between 0 and N.
3. **A**: Minimum dirtiness threshold to consider a leaf for discarding, randomly generated between 1 and 1000.
4. **B**: Maximum dirtiness threshold to reconsider a leaf for discarding, randomly generated between A and 1000 to ensure \(A \leq B\).
5. **D**: List of dirtiness values for each leaf, randomly generated between 1 and 1000 for N leaves.
This generator ensures that the generated values conform to the given constraints and provide a variety of test cases for thorough testing.
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