Problem p03396 - Generation 3

Orig Description

Score : 1600 points
Problem StatementYui loves shopping. She lives in Yamaboshi City and there is a train service in the city. The city can be modelled as a very long number line. Yui's house is at coordinate 0.
There are N shopping centres in the city, located at coordinates x_{1}, x_{2}, ..., x_{N} respectively. There are N + 2 train stations, one located at coordinate 0, one located at coordinate L, and one located at each shopping centre.
At time 0, the train departs from position 0 to the positive direction. The train travels at a constant speed of 1 unit per second. At time L, the train will reach the last station, the station at coordinate L. The train immediately moves in the opposite direction at the same speed. At time 2L, the train will reach the station at coordinate 0 and it immediately moves in the opposite direction again. The process repeats indefinitely.
When the train arrives at a station where Yui is located, Yui can board or leave the train immediately. At time 0, Yui is at the station at coordinate 0. 
Yui wants to go shopping in all N shopping centres, in any order, and return home after she finishes her shopping. She needs to shop for t_{i} seconds in the shopping centre at coordinate x_{i}. She must finish her shopping in one shopping centre before moving to the next shopping centre. Yui can immediately start shopping when she reaches a station with a shopping centre and she can immediately board the train when she finishes shopping.
Yui wants to spend the minimum amount of time to finish her shopping. Can you help her determine the minimum number of seconds required to complete her shopping?
Constraints
1 \leq N \leq 300000
1 \leq L \leq 10^{9}
0 < x_{1} < x_{2} < ... < x_{N} < L
1 \leq t_{i} \leq 10^{9}
All values in the input are integers.
Partial Score
1000 points will be awarded for passing the testset satisfying 1 \leq N \leq 3000.
InputInput is given from Standard Input in the following format:
N L
x_{1} x_{2} ... x_{N}
t_{1} t_{2} ... t_{N}
OutputPrint the minimum time (in seconds) required for Yui to finish shopping at all N shopping centres and return home.
Sample Input 12 10
5 8
10 4
Sample Output 140
Here's one possible way for Yui to finish her shopping :
Travel to the station at coordinate 8 with the train. She arrives at coordinate 8 at time 8.
Shop in the shopping centre at coordinate 8. She finishes her shopping at time 12.
The train arrives at coordinate 8 at time 12. She boards the train which is currently moving in the negative direction.
She arrives at coordinate 5 at time 15. She finishes her shopping at time 25.
The train arrives at coordinate 5 at time 25. She boards the train which is currently moving in the positive direction.
She arrives at coordinate L = 10 at time 30. The train starts moving in the negative direction immediately.
She arrives at coordinate 0 at time 40, ending the trip.
Sample Input 22 10
5 8
10 5
Sample Output 260
Sample Input 35 100
10 19 28 47 68
200 200 200 200 200
Sample Output 31200
Sample Input 48 1000000000
2018 123456 1719128 1929183 9129198 10100101 77777777 120182018
99999999 1000000000 1000000000 11291341 1 200 1 123812831
Sample Output 414000000000
Beware of overflow issues.

Extracted Specification

An integer N (1 ≤ N ≤ 300000), representing some quantity or size.
An integer L (1 ≤ L ≤ 10^9), representing some coordinate or distance.
A list of integers X of size N, where each integer is between 1 and L-1 and sorted in strictly increasing order.
A list of integers T of size N, where each integer is between 1 and 10^9.

### Example Input:

```
2 10
5 8
10 4
```

### Function Signature:
Write a function f(N, L, X, T) that takes in the input.
```python
def f(N: int, L: int, X: List[int], T: List[int]):
    '''
    N: an integer
    L: an integer
    X: a list of integers
    T: a list of integers
    '''

Test Case Generator

Sure, I can help you write a test case generator for the given problem. Here's the generator script:

```python
import random

def tcgen():
    # Constraints
    N = random.randint(1, 300000)
    L = random.randint(1, 10**9)
    
    # Generate N unique shopping centre coordinates sorted in increasing order
    x = sorted(random.sample(range(1, L), N))

    # Generate N shopping times
    t = [random.randint(1, 10**9) for _ in range(N)]

    return N, L, x, t

# Example usage
if __name__ == "__main__":
    N, L, x, t = tcgen()
    print(N)
    print(L)
    print(" ".join(map(str, x)))
    print(" ".join(map(str, t)))
```

### Explanation:
1. **N**: The number of shopping centres is generated randomly between 1 and 300,000.
2. **L**: The coordinate of the last station is generated randomly between 1 and \(10^9\).
3. **x**: A sorted list of unique coordinates for the shopping centres is generated. This is done by generating a random sample of `N` unique integers in the range \([1, L-1]\) and then sorting them.
4. **t**: A list of shopping times, each randomly generated between 1 and \(10^9\).

The generator ensures that the generated input adheres to the constraints provided in the problem statement.

### Example Output:
Running the above generator might produce output similar to this:

```
123456
987654321
1234 5678 91011 121314 151617 181920 ... (and so on)
23456 78901 23456 78901 23456 78901 ... (and so on)
```

Feel free to use this generator to create various test cases and test your solution against them.

Extract Arguments

def extract_arguments(fh):
    N, L = map(int, fh.readline().strip().split())
    x = list(map(int, fh.readline().strip().split()))
    t = list(map(int, fh.readline().strip().split()))
    return N, L, x, t