#K51887. Maximum Resource Collection
Maximum Resource Collection
Maximum Resource Collection
You are given an integer n and a list of n integers. Each integer represents the amount of resources available at a particular location. Simon wants to maximize the amount of resources he collects in one trip by visiting at most two consecutive locations.
If there is only a single location, then the answer is simply the resource at that location. Otherwise, you should select two consecutive locations such that their sum is maximized. In mathematical terms, when n > 1, you need to compute
\(\max_{0 \leq i < n-1} \{resources[i] + resources[i+1]\}\)
and if n = 1, then the answer is resources[0].
inputFormat
The first line contains an integer n representing the number of locations. The second line contains n space-separated integers, which denote the resources available at each location.
outputFormat
Output a single integer representing the maximum amount of resources that Simon can collect by visiting at most two consecutive locations.
## sample1
4
4
</p>