Please write a program that maintains a sequence, supporting the following operations:
Operation | Input Format | Description |
---|---|---|
1. Reverse | REVERSE | Reverse the entire sequence. |
2. Get Sum | GET-SUM posi tot | Starting at the -th number in the current sequence, output the sum of consecutive numbers. |
3. Max Sum | MAX-SUM | Output the largest sum of any (non-empty) consecutive subsequence of the current sequence. |
Input Specification
The first line of input contains two integers and , where is the initial length of the sequence and is the number of operations.
The second line of input contains integers, describing the initial sequence.
For the next lines, each line will contain a command in one of the formats described above.
Output Specification
For each GET-SUM or MAX-SUM operation in the input, output the result of the query on a separate line.
Sample Input
9 7
2 -6 3 5 1 -5 -3 6 3
GET-SUM 5 4
REVERSE
GET-SUM 5 4
MAX-SUM
GET-SUM 3 6
REVERSE
GET-SUM 1 2
Sample Output
-1
3
10
-5
-4
Constraints
The data in the input is guaranteed to be valid, and will always refer to existing positions in the sequence.
In test data worth of the points, .
In test data worth of the points, .
In test data worth of the points, the value of any number in the sequence will be in the range .
In test data worth of the points, .
Comments