#SGM0000011. Truy vấn tổng đoạn con lớn nhất I (Can you answer these queries I)
Truy vấn tổng đoạn con lớn nhất I (Can you answer these queries I)
Can you answer these queries I
Source: SPOJ
Version: Phuoc Hung OJ Extended
Given an array , each query asks for the maximum sum of a non-empty contiguous subarray fully contained in :
Input
The first line contains .
The second line contains the array.
The third line contains .
Each of the next lines contains .
Output
For each query, print the maximum contiguous subarray sum.
Subtasks
- Subtask 1 — 20%: , .
- Subtask 2 — 30%: , .
- Subtask 3 — 50%: , , .
Examples
Input
3
-1 2 3
1
1 2
Output
2
Explanation
The sample follows the operations exactly; each printed line corresponds to a query that requires output.