Codeforces Round 381 (Div. 2)
B
Alyona and flowers
Codeforces
1200
原题
← AC →
翻译中…

Little Alyona is celebrating Happy Birthday! Her mother has an array of $*n*$ flowers. Each flower has some mood, the mood of $*i*$-th flower is $*a*_{*i*}$. The mood can be positive, zero or negative.

翻译中…

Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.

翻译中…

For example, consider the case when the mother has $5$ flowers, and their moods are equal to $1,  - 2, 1, 3,  - 4$. Suppose the mother suggested subarrays $(1,  - 2)$, $(3,  - 4)$, $(1, 3)$, $(1,  - 2, 1, 3)$. Then if the girl chooses the third and the fourth subarrays then:

翻译中…
  • the first flower adds $1·1 = 1$ to the girl's happiness, because he is in one of chosen subarrays,
  • the second flower adds $( - 2)·1 = - 2$, because he is in one of chosen subarrays,
  • the third flower adds $1·2 = 2$, because he is in two of chosen subarrays,
  • the fourth flower adds $3·2 = 6$, because he is in two of chosen subarrays,
  • the fifth flower adds $( - 4)·0 = 0$, because he is in no chosen subarrays.
翻译中…

Thus, in total $1 + ( - 2) + 2 + 6 + 0 = 7$ is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!

翻译中…

Alyona can choose any number of the subarrays, even $0$ or all suggested by her mother.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 100$) — the number of flowers and the number of subarrays suggested by the mother.

翻译中…

The second line contains the flowers moods — $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($- 100 ≤ *a*_{*i*} ≤ 100$).

翻译中…

The next $*m*$ lines contain the description of the subarrays suggested by the mother. The $*i*$-th of these lines contain two integers $*l*_{*i*}$ and $*r*_{*i*}$ ($1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *n*$) denoting the subarray $*a*[*l*_{*i*}], *a*[*l*_{*i*} + 1], ..., *a*[*r*_{*i*}]$.

翻译中…

Each subarray can encounter more than once.

翻译中…

Output

翻译中…

Print single integer — the maximum possible value added to the Alyona's happiness.

翻译中…

Note

翻译中…

The first example is the situation described in the statements.

翻译中…

In the second example Alyona should choose all subarrays.

翻译中…

The third example has answer $0$ because Alyona can choose none of the subarrays.

翻译中…

样例

Input #1
5 4
1 -2 1 3 -4
1 2
4 5
3 4
1 4
Output #1
7
InputCopy OutputCopy
Input #2
4 3
1 2 3 4
1 3
2 4
1 1
Output #2
16
InputCopy OutputCopy
Input #3
2 2
-1 -2
1 1
1 2
Output #3
0
InputCopy OutputCopy
题目信息
题号
740B
时间限制
2 s
内存限制
256 MB
标签
构造

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。