303838: CF740B. Alyona and flowers
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Alyona and flowers
题意翻译
给一个长度为 n 的序列,然后给 m 个区间,你可以任意选择几个区间,求所有选择中区间的和最大是多少?题目描述
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.输入输出格式
输入格式
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.
输出格式
Print single integer — the maximum possible value added to the Alyona's happiness.
输入输出样例
输入样例 #1
5 4
1 -2 1 3 -4
1 2
4 5
3 4
1 4
输出样例 #1
7
输入样例 #2
4 3
1 2 3 4
1 3
2 4
1 1
输出样例 #2
16
输入样例 #3
2 2
-1 -2
1 1
1 2
输出样例 #3
0