Orig Description
F: Absum
Problem
You are given a sequence $A$ of length $N$. You can perform at most $M$ operations to swap the $i$-th and $j$-th ($0 \leq i, j \leq N-1$) elements of the sequence.
Find the maximum possible value of $\sum_{i = 0}^{N - 1} abs(A_i - i)$ over all possible sequences that can be obtained by performing the operations.
Constraints
$2 \leq N \leq 10^5$
$0 \leq M \leq N$
$0 \leq A_i \leq 10^5$
Input format
The input is given in the following format:
$N\ M$
$A_0\ A_1\ A_2\ \dots\ A_{N - 1}$
Output format
Print the maximum value of $\sum_{i = 0}^{N - 1} abs(A_i - i)$ over all possible sequences that can be obtained by performing the operations. Print a newline character at the end.
Sample Input 1
5 2
0 3 2 1 4
Sample Output 1
12
Swap the $0$-th and $4$-th elements to obtain the sequence $(4, 3, 2, 1, 0)$. The maximum value of $\sum_{i = 0}^{N - 1} abs(A_i - i)$ is $|4 - 0| + |3 - 1| + |2 - 2| + |1 - 3| + |0 - 4| = 12$. Note that it is not necessary to perform exactly $M$ operations.
Sample Input 2
3 2
0 0 0
Sample Output 2
3
The maximum value is obtained without performing any operations.
Sample Input 3
6 2
1 0 3 6 5 4
Sample Output 3
20
Extracted Specification
An integer N (2 ≤ N ≤ 10^5), representing some quantity or size.
An integer M (0 ≤ M ≤ N), representing some limit on operations.
A list of integers A of size N, where each integer is between 0 and 1e5.
### Example Input:
```
5 2
0 3 2 1 4
```
### Function Signature:
Write a function f(N, M, A) that takes in the input.
def f(N: int, M: int, A: List[int]):
'''
N: an integer
M: an integer
A: a list of integers
'''
Test Case Generator
Sure, I can help you write a test case generator for the given problem statement "F: Absum". Here's a Python function that generates random test cases based on the constraints provided:
```python
import random
def tcgen():
# Generate a random integer N (2 ≤ N ≤ 10^5)
N = random.randint(2, 10**5)
# Generate a random integer M (0 ≤ M ≤ N)
M = random.randint(0, N)
# Generate a list of N integers A (0 ≤ A_i ≤ 10^5)
A = [random.randint(0, 10**5) for _ in range(N)]
return N, M, A
# Example usage:
if __name__ == "__main__":
N, M, A = tcgen()
print(N, M)
print(' '.join(map(str, A)))
```
### Explanation:
1. **N Generation**:
- `N = random.randint(2, 10**5)` generates a random integer \( N \) within the range [2, 100000].
2. **M Generation**:
- `M = random.randint(0, N)` generates a random integer \( M \) within the range [0, \( N \)].
3. **A Generation**:
- `A = [random.randint(0, 10**5) for _ in range(N)]` generates a list \( A \) of \( N \) integers, each within the range [0, 100000].
The generator function creates random inputs that conform to the constraints specified in the problem statement. The example usage demonstrates how to generate a test case and print it in the required format.
You can run the script to generate random test cases for testing your solution.
Extract Arguments
def extract_arguments(fh):
N, M = map(int, fh.readline().strip().split())
A = list(map(int, fh.readline().strip().split()))
return N, M, A