问题 AL: Editor
内存限制:128 MB
时间限制:1.000 S
评测方式:文本比较
命题人:
提交:115
解决:27
题目描述
You are going to implement the most powerful editor for integer sequences.
The sequence is empty when the editor is initialized.
There are 5 types of instructions.
- I x Insert x after the cursor.
- D Delete the element before the cursor.
- L Move the cursor left unless it has already been at the begin.R Move the cursor right unless it has already been at the end.
- Q k Suppose that the current sequence BEFORE the cursor is {a1,a2…an}. Find max1≤i≤k Si where Si=a1+a2+⋅⋅+a¡
输入
The input file consists of multiple test cases. For each test case:
The first line contains an integer Q, which is the number of instructions. The next Q lines contain an instruction asdescribed above.
(1<Q<106,|x|<103 for I instruction, 1<k<n. for Q instruction)
The first line contains an integer Q, which is the number of instructions. The next Q lines contain an instruction asdescribed above.
(1<Q<106,|x|<103 for I instruction, 1<k<n. for Q instruction)
输出
For each Q instruction, output the desired value.
样例输入 复制
8
I 2
I -1
I 1
Q 3
L
D
R
Q 2
样例输出 复制
2
3
提示
The following diagram shows the status of sequence after each instruction:
1≤Q≤106
∣x∣≤103
1≤k≤n
1≤Q≤106
∣x∣≤103
1≤k≤n