1576.Kuangyeye and hamburgers

Time Limit: 1s Memory Limit: 256MB

Kuangyeye is a dalao of the ACM school team of Hunan University. His favorite food are hamburgers. One day, Kuangyeye came to the KFC(or maybe McDonald) and saw $n$ hamburgers on the counter. The weight of the $i$-th hamburger was $w_i$. Since he likes hamburgers very much, he would like to buy some hamburgers. Considering his weight or other factors, Kuangyeye only wanted to eat all the hamburgers from the $a$-th heaviest to the $b$-th. Since Kuangyeye is fickle, he had $k$ plans before buying hamburgers. The $i$-th plan gives $a_i$ and $b_i$. Please help Kuangyeye calculate the maximum weight of hamburgers he can eat among the $k$ plans.

Input Format(From the terminal/stdin)

The first line of input contains two integer $n$ and $k$ --the number of hamburgers on the counter
and the number of plans Kuangyeye had;
the next line contains $n$ integer--the $i$-th integer represents the weight of $i$-th hamburger, namely
$w_i$;
Each the following $k$ line contains two integer $a_i$ and $b_i$ ,represents Kuangyeye's strategy in his $i$-th plan.

Output Format(To the terminal/stdout)

Output contain a single integer, represents maximum weight of hamburgers Kuangyeye can eat.

Sample Input

Copy
5 2
4 3 5 2 6
1 1
3 4
 · \n
 · · · · \n
 · \n
 · \n

Sample Output

Copy
7
 \n

Hints

Kuangyeye's first plan was to eat the hamburger weighing $6$;
and his second plan was to eat the hamburger weighing $3$ and $4$;
So the maximum weight of hamburgers he can eat was $7$.
$1≤n,k≤100000,1≤a_i≤b_i≤n,1≤w_i≤10000$.

Source: 2018 HNU新生赛

Submit

请先 登录

© 2025 FAQs