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 quantity.
A list of integers A of size N, where each integer is between 0 and 10^5.
### 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 create a test case generator for the given problem statement "F: Absum". Here is the code for the test case generator:
```python
import random
def tcgen():
# Generate a random value for N within the given constraints
N = random.randint(2, 10**5)
# Generate a random value for M within the given constraints
M = random.randint(0, N)
# Generate the array A with N elements, each between 0 and 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 of the Generator
1. **N Generation**:
- The number of elements \( N \) is randomly selected from the range [2, \( 10^5 \)].
2. **M Generation**:
- The number of operations \( M \) is randomly selected from the range [0, \( N \)].
3. **Array A Generation**:
- The elements of the array \( A \) are randomly selected integers from the range [0, \( 10^5 \)].
### Example Output
Running the `tcgen` function will give you a random test case:
```
5 3
98237 12345 67890 54321 98765
```
This output means:
- \( N = 5 \)
- \( M = 3 \)
- \( A = [98237, 12345, 67890, 54321, 98765] \)
You can use this generator to create multiple test cases for your problem.
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
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, M, A = extract_arguments(fh)
# f(N, M, A)