Problem p01791 - Generation 2

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.
An integer \( k \) (1 ≤ \( k \) ≤ \( n \)), another quantity.
An integer \( a \) (0 ≤ \( a \) ≤ 180,000), a lower bound.
An integer \( b \) (0 ≤ \( a \) ≤ \( b \) ≤ 180,000), an upper bound.
A list of \( n \) integers \( x \) (0 ≤ \( x_i \) ≤ 300).

### Example Input:

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

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

Test Case Generator

Sure! Here's a test case generator for the "Card Game Strategy" problem:

```python
import random

def tcgen():
    n = random.randint(1, 600)
    k = random.randint(1, n)
    a = random.randint(0, 180000)
    b = random.randint(a, 180000)
    x = [random.randint(0, 300) for _ in range(n)]
    
    return n, k, a, b, x

# Example of generating a test case
n, k, a, b, x = tcgen()
print(f"{n} {k} {a} {b}")
print(" ".join(map(str, x)))
```

### Explanation:
1. **n**: The number of cards is randomly chosen between 1 and 600.
2. **k**: The number of cards Bob chooses is randomly chosen between 1 and n.
3. **a**: The lower bound of the integer Alice can choose is randomly chosen between 0 and 180000.
4. **b**: The upper bound is randomly chosen between a and 180000 to ensure \(a \leq b\).
5. **x**: The integers on the cards are randomly chosen between 0 and 300.

The generator prints the values of \(n, k, a, b\) on the first line and the list of integers on the second line, as expected in the problem statement.

### Example Output:
```
n k a b
x1 x2 x3 ... xn
```

This output format can be directly used as input for the problem to verify the correctness of any implemented solution.

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)