Circle - MarisaOJ: Marisa Online Judge

Circle

Time limit: 1000 ms
Memory limit: 256 MB
Consider $n$ points lying on a circle. Let $A_i$ be the distance from point $i$ to $i+1$ on the circle. Find the shortest distance from point $x$ to point $y$ on the circle. ### Input - The first line consists of an integer $n$. - The second line contains $n$ integers $A_i$. Where $A_n$ is the distance from point $n$ to point $1$. - The third line contains two integers $x$ and $y$. ### Output - Output the shortest distance between points $x$ and $y$. ### Constraints - $1 \le n \le 1000$. - $1 \le x, y \le n$. - $1 \le A_i \le 1000$. ### Sample test ``` 3 1 2 2 1 3 ``` Output: ``` 2 ```