22043_CircularSequence

2022-5-16 18:21| 发布者: Hocassian| 查看: 19| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-8950664610299-Problem List-采集的数据-后羿采集器.html

Pro.ID

22043

Title

Circular Sequence

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22043

AC

11

Submit

82

Ratio

13.41%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Given a sequence with n elements, if the last element is also adjacent to the first element of the sequence, the sequence is call "circular sequence".

    Now, here comes a simple problem: given a circular sequence, you should find a segment of the sequence, such that it contains at least one element, and the sum of the elements is as large as possible.

    输入

    Input may contain several test cases. The first line is a single integer t, the number of test cases below. Each test case composed of two lines. The first line of each test case is a positive integer n ( 1 ≤ n ≤ 100000 ), denoting the number of elements in the circular sequence, and the second line has n integers; the absolute value of each integer is no more than 100000.

    输出

    Description

    Given a sequence with n elements, if the last element is also adjacent to the first element of the sequence, the sequence is call "circular sequence".

    Now, here comes a simple problem: given a circular sequence, you should find a segment of the sequence, such that it contains at least one element, and the sum of the elements is as large as possible.

    Input

    Input may contain several test cases. The first line is a single integer t, the number of test cases below. Each test case composed of two lines. The first line of each test case is a positive integer n ( 1 ≤ n ≤ 100000 ), denoting the number of elements in the circular sequence, and the second line has n integers; the absolute value of each integer is no more than 100000.

    Output

    For each test case, output the maximum segment sum in a single line.

    Sample Input

    2
    2
    -1 -2
    3
    1 -2 3

    Sample Output

    -1
    4

    Source

    样例输入

    2
    2
    -1 -2
    3
    1 -2 3

    样例输出

    -1
    4

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部