Problem p01791 - Generation 3

Orig Description

Problem B
Card Game Strategy
Alice and Bob are going to play a card game. There are $n$ cards, each having an integer written on it. The game proceeds as follows:
 Alice chooses an integer between $a$ and $b$, inclusive. Call this integer $t$. Alice then tells Bob the value of $t$.
 Bob chooses $k$ out of the $n$ cards. Compute the sum of the integers written on the $k$ cards Bob chooses. Call this sum $u$.
Alice's objective is to make $|t - u|$ as large as possible and Bob's is to make $|t - u|$ as small as possible.
Prior to the game, both Alice and Bob know the values of $n$, $k$, $a$, and $b$, and also the integers on the cards. Both Alice and Bob will play optimally. In particular, Alice will make a choice, knowing that Bob will surely minimize $|t - u|$ for told $t$. Additionally, assume that Alice prefers to choose smaller $t$ if she has multiple equally good choices.
Your task is to determine the outcome of the game: the value of $t$ Alice will choose and the $k$ cards Bob will choose for that $t$.
Input
The input consists of two lines representing a single test case. The first line contains four integers $n$, $k$, $a$, and $b$ $(1 \leq k \leq n \leq 600, 0 \leq a \leq b \leq 180,000)$. The second line contains $n$ integers $x_1, ...,  x_n$ $(0 \leq x_i \leq 300)$, denoting that $x_i$ is written on the $i$-th card.
Output
Display two lines: The first line should contain an integer representing the value of $t$ Alice will choose. The second line should contain k distinct integers between 1 and $n$, inclusive, representing the indices of the cards Bob will choose. If Bob has multiple equally good choices, display any one of them.
Sample Input 1
4 2 58 100
10 10 50 80
Output for the Sample Input 1
75
2 3
Sample Input 2
8 3 1300 1800
2 0 1 5 0 4 1 9
Output for the Sample Input 2
1800
4 6 8

Extracted Specification

An integer \( n \) (1 ≤ \( k \) ≤ \( n \) ≤ 600), representing some quantity or size.
An integer \( k \) (1 ≤ \( k \) ≤ \( n \)), representing another quantity.
An integer \( a \) (0 ≤ \( a \)).
An integer \( b \) (\( a \) ≤ \( b \) ≤ 180,000).
A list of \( n \) integers where each integer \( x_i \) (0 ≤ \( x_i \) ≤ 300).

### Example Input:

```
4 2 58 100
10 10 50 80
```

### Function Signature:
Write a function f(n, k, a, b, x) that takes in the input. 
```python
def f(n: int, k: int, a: int, b: int, x: List[int]):
    '''
    n: an integer
    k: an integer
    a: an integer
    b: an integer
    x: a list of integers
    '''
```

Test Case Generator

Here is a test case generator for "Problem B: Card Game Strategy":

First, let’s analyze the requirements and constraints:

1. \( n \) (1 ≤ \( k \) ≤ \( n \) ≤ 600): the number of cards.
2. \( k \) (1 ≤ \( k \) ≤ \( n \)): the number of cards Bob will choose.
3. \( a \) and \( b \) (0 ≤ \( a \) ≤ \( b \) ≤ 180,000): the range from which Alice will choose an integer \( t \).
4. A list of integers \( x \), each between 0 and 300, representing the integers written on the cards.

Given these constraints, we can create a test case generator as follows:

```python
import random

def tcgen():
    # Generating random values for n, k, a, and b within the given constraints
    n = random.randint(1, 600)
    k = random.randint(1, n)
    a = random.randint(0, 180000)
    b = random.randint(a, 180000)  # Ensure b is at least as large as a
    
    # Generating a list of n integers, each between 0 and 300
    x = [random.randint(0, 300) for _ in range(n)]
    
    # Returning the generated values
    return n, k, a, b, x

# Example usage of the generator:
n, k, a, b, x = tcgen()
print(n, k, a, b)
print(' '.join(map(str, x)))
```

### Explanation:
1. **n** is chosen randomly between 1 and 600.
2. **k** is chosen randomly between 1 and **n**.
3. **a** is chosen randomly between 0 and 180,000.
4. **b** is chosen randomly between **a** and 180,000 to ensure that **a** ≤ **b**.
5. A list of **n** integers is generated, where each integer is between 0 and 300.

This generator will produce random test cases that conform to the problem’s constraints. The output can be used directly in competitive programming platforms to test different scenarios of the "Card Game Strategy" problem.

Extract Arguments

def extract_arguments(fh):
    n, k, a, b = map(int, fh.readline().strip().split())
    x = list(map(int, fh.readline().strip().split()))
    return n, k, a, b, x

# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh:
#         n, k, a, b, x = extract_arguments(fh)
#         f(n, k, a, b, x)