Problem 2984 --Keen On Everything But Triangle

2984: Keen On Everything But Triangle

"
Time Limit $3$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $2$ 正确数量 $2$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
N sticks are arranged in a row, and their lengths are a1,a2,...,aNa1,a2,...,aN

There are QQ querys. For ii-th of them, you can only use sticks between lili-th to riri-th. Please output the maximum circumference of all the triangles that you can make with these sticks, or print −1−1 denoting no triangles you can make.
There are multiple test cases. 

Each case starts with a line containing two positive integers N,Q(N,Q≤105)N,Q(N,Q≤105)

The second line contains NN integers, the ii-th integer ai(1≤ai≤109)ai(1≤ai≤109) of them showing the length of the ii-th stick. 

Then follow QQ lines. ii-th of them contains two integers li,ri(1≤li≤ri≤N)li,ri(1≤li≤ri≤N), meaning that you can only use sticks between lili-th to riri-th. 

It is guaranteed that the sum of NNs and the sum of QQs in all test cases are both no larger than 4×1054×105.
For each test case, output QQ lines, each containing an integer denoting the maximum circumference.
5 3
2 5 6 5 2
1 3
2 4
2 5
13
16
16

推荐代码 查看2984 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$763 $ms] 刘成健 458848 2019-08-17 20:11:00
内存最少[$0 $KB] 淡意的温柔 591121 2020-06-06 08:14:44
第一AC 刘成健 458848 2019-08-17 20:11:00
第一挑战 刘成健 458848 2019-08-17 20:11:00

赛题来源/所属竞赛 2019 Multi-University Training Contest 2 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛