Island
Time limit3sMemory limit512 MB
Given the edge lengths of a cycle, find the maximum over all pairs of towns of the shorter of the two arc distances.
- Level
Medium5 of 10
- Topics
- Two pointers, Prefix sum, Array
- Solved
- No attempts yet
Problem
On the island of Byteland, every town lies along the seashore, and the towns are arranged in a ring. A single two-way ring road runs along the coast and links all the towns in order, so from any town you can reach any other town by traveling either clockwise or counterclockwise around the ring. The distance between two towns is defined as the length of the shorter of these two routes.
Fans of two rival football teams want to watch the match from towns that are as far apart as possible. Determine the largest distance that can separate two towns on the island.
Write a program that:
- reads a description of the island from standard input,
- computes the maximum possible distance between any two towns,
- writes that distance to standard output.
Input
The first line contains one integer (), the number of towns, numbered through in order around the ring.
Each of the next lines contains one positive integer giving the length of a ring-road section. For , line contains the length of the road between town and town . Line contains the length of the road between town and town .
The total length of the ring road does not exceed .
Output
Print one integer: the maximum distance that can separate two towns.