Orig Description
Score : 200 points
Problem StatementWe have N weights indexed 1 to N. The mass of the weight indexed i is W_i.
We will divide these weights into two groups: the weights with indices not greater than T, and those with indices greater than T, for some integer 1 \leq T < N. Let S_1 be the sum of the masses of the weights in the former group, and S_2 be the sum of the masses of the weights in the latter group.
Consider all possible such divisions and find the minimum possible absolute difference of S_1 and S_2.
Constraints
2 \leq N \leq 100
1 \leq W_i \leq 100
All values in input are integers.
InputInput is given from Standard Input in the following format:
N
W_1 W_2 ... W_{N-1} W_N
OutputPrint the minimum possible absolute difference of S_1 and S_2.
Sample Input 13
1 2 3
Sample Output 10
If T = 2, S_1 = 1 + 2 = 3 and S_2 = 3, with the absolute difference of 0.
Sample Input 24
1 3 1 1
Sample Output 22
If T = 2, S_1 = 1 + 3 = 4 and S_2 = 1 + 1 = 2, with the absolute difference of 2. We cannot have a smaller absolute difference.
Sample Input 38
27 23 76 2 3 5 62 52
Sample Output 32
Extracted Specification
Canonicalized Input Description:
An integer N (2 ≤ N ≤ 100), representing some quantity or size.
A list of integers W of size N, where each integer is between 1 and 100.
### Example Input:
```
3
1 2 3
```
### Function Signature:
Write a function f(N, W) that takes in the input.
def f(N: int, W: List[int]):
'''
N: an integer
W: a list of integers
'''
Test Case Generator
Sure! Here is a test case generator for the described problem:
```python
import random
def tcgen():
# Set the constraints
N = random.randint(2, 100)
W = [random.randint(1, 100) for _ in range(N)]
return N, W
# Example usage:
N, W = tcgen()
print(N)
print(" ".join(map(str, W)))
```
To explain the generator:
1. **N**: Generates a random integer between 2 and 100 (inclusive), representing the number of weights.
2. **W**: Generates a list of N random integers between 1 and 100 (inclusive), representing the masses of the weights.
This will provide random test cases conforming to the problem's constraints. Here's how you can run the generator to see a sample test case:
```python
if __name__ == "__main__":
N, W = tcgen()
print(N)
print(" ".join(map(str, W)))
```
When you run this code, it will output a random test case in the format expected by the problem statement.
Extract Arguments
def extract_arguments(fh):
N = int(fh.readline().strip())
W = list(map(int, fh.readline().strip().split()))
return N, W
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, W = extract_arguments(fh)
# f(N, W)