Problem 01C. Best Subarray Through a Point ≡

Author:Pavel Mesenev   Time limit:2 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

You are given an array of n integers a0, a1, …, an − 1, some of which may be negative, and q independent queries. Each query is an index p (0 ≤ p ≤ n − 1).

For a query p, consider every non-empty contiguous block al, …, ar that contains position p, that is l ≤ p ≤ r. Output the largest possible value of al + al + 1 + …  + ar among those blocks.

Input format

The first line contains two integers n and q. The second line contains n space-separated integers a0… an − 1. The third line contains q space-separated integers — the query indices.

Output format

Print q lines; line j is the answer to the j-th query.

Constraints

1 ≤ n ≤ 2 ⋅ 105

1 ≤ q ≤ 2 ⋅ 105

 − 109 ≤ ai ≤ 109

Every answer fits into a signed 64-bit integer.

Sample tests

No. Standard input Standard output
1
9 3
-2 1 -3 4 -1 2 1 -5 4
6 0 8
6
2
5
2
1 1
-5
0
-5
3
5 3
-1 -2 -3 -4 -5
0 2 4
-1
-3
-5

0.036s 0.009s 18