| Author: | Pavel Mesenev | Time limit: | 2 sec | |
| Input file: | Standard input | Memory limit: | 256 Mb | |
| Output file: | Standard output |
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.
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.
Print q lines; line j is the answer to the j-th query.
1 ≤ n ≤ 2 ⋅ 105
1 ≤ q ≤ 2 ⋅ 105
− 109 ≤ ai ≤ 109
Every answer fits into a signed 64-bit integer.
| No. | Standard input | Standard output |
|---|---|---|
| 1 |
|
|
| 2 |
|
|
| 3 |
|
|