#B4315. Longest Time on Subway

    ID: 11971 Type: Default 1000ms 256MiB

Longest Time on Subway

Longest Time on Subway

The subway passes through n stations numbered from $1$ to $n$. It takes $t_i$ seconds to travel from station $i$ to station $i+1$, and upon arriving at station $i$, the train stops for $s_i$ seconds.

Little M wants to ride the subway from station $x$ to station $y$. The longest time he can spend on the subway is defined as the scenario where he boards the train immediately as it arrives at station $x$ and only gets off just before the train departs from station $y$. Compute this maximum time in seconds.

Note: Under this scenario, the time spent on the subway is calculated as:

$\displaystyle \sum_{i=x}^{y-1} t_i + \sum_{i=x+1}^{y} s_i$

inputFormat

The first line contains three integers n, x, and y ($2 \le n \le 10^5$, $1 \le x < y \le n$) separated by spaces.

The second line contains n-1 integers, representing $t_1, t_2, \ldots, t_{n-1}$, where $t_i$ is the travel time in seconds from station $i$ to station $i+1$.

The third line contains n integers, representing $s_1, s_2, \ldots, s_n$, where $s_i$ is the stop time in seconds at station $i$.

outputFormat

Output a single integer representing the longest time (in seconds) that Little M can spend on the subway, computed as:

$\displaystyle \sum_{i=x}^{y-1} t_i + \sum_{i=x+1}^{y} s_i$

sample

5 2 4
2 3 4 5
1 2 3 4 5
14