#K15941. Maximum Adjacent Sum in a Circular Array

    ID: 24468 Type: Default 1000ms 256MiB

Maximum Adjacent Sum in a Circular Array

Maximum Adjacent Sum in a Circular Array

You are given several test cases. In each test case, you are given an integer n and an array of n integers representing the ratings of restaurants arranged in a circle. Because the restaurants are arranged in a circular manner, the first and the last elements are considered adjacent.

Your task is to determine the maximum sum of the ratings of any two adjacent restaurants. Formally, for an array \( A \) of length \( n \), you need to find:

\[ \max\{A[i] + A[i+1] \mid 0 \leq i \leq n-2\} \cup \{A[n-1] + A[0]\} \]

Note: \( n \) is at least 2, and the ratings can be very large. Make sure your solution handles large numbers appropriately.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains a single integer \( T \), the number of test cases.
  2. Each test case consists of two lines:
    1. The first line of a test case contains an integer \( n \) — the number of restaurants.
    2. The second line contains \( n \) space-separated integers representing the ratings.

outputFormat

For each test case, output a single line containing the maximum sum of the ratings of two adjacent restaurants as described above. The output should be printed to standard output (stdout).

## sample
3
4
1 3 2 5
5
6 1 10 7 10
3
7 7 7
7

17 14

</p>