CF515E.Drazil and Park

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Drazil is a monkey. He lives in a circular park. There are nn trees around the park. The distance between the ii -th tree and ( i+1i+1 )-st trees is did_{i} , the distance between the nn -th tree and the first tree is dnd_{n} . The height of the ii -th tree is hih_{i} .

Drazil starts each day with the morning run. The morning run consists of the following steps:

  • Drazil chooses two different trees
  • He starts with climbing up the first tree
  • Then he climbs down the first tree, runs around the park (in one of two possible directions) to the second tree, and climbs on it
  • Then he finally climbs down the second tree.

But there are always children playing around some consecutive trees. Drazil can't stand children, so he can't choose the trees close to children. He even can't stay close to those trees.

If the two trees Drazil chooses are xx -th and yy -th, we can estimate the energy the morning run takes to him as 2(hx+hy)+dist(x,y)2(h_{x}+h_{y})+dist(x,y) . Since there are children on exactly one of two arcs connecting xx and yy , the distance dist(x,y)dist(x,y) between trees xx and yy is uniquely defined.

Now, you know that on the ii -th day children play between aia_{i} -th tree and bib_{i} -th tree. More formally, if ai<=bia_{i}<=b_{i} , children play around the trees with indices from range [ai,bi][a_{i},b_{i}] , otherwise they play around the trees with indices from .

Please help Drazil to determine which two trees he should choose in order to consume the most energy (since he wants to become fit and cool-looking monkey) and report the resulting amount of energy for each day.

输入格式

The first line contains two integer nn and mm ( 3<=n<=1053<=n<=10^{5} , 1<=m<=1051<=m<=10^{5} ), denoting number of trees and number of days, respectively.

The second line contains nn integers d1,d2,...,dnd_{1},d_{2},...,d_{n} ( 1<=di<=1091<=d_{i}<=10^{9} ), the distances between consecutive trees.

The third line contains nn integers h1,h2,...,hnh_{1},h_{2},...,h_{n} ( 1<=hi<=1091<=h_{i}<=10^{9} ), the heights of trees.

Each of following mm lines contains two integers aia_{i} and bib_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n ) describing each new day. There are always at least two different trees Drazil can choose that are not affected by children.

输出格式

For each day print the answer in a separate line.

输入输出样例

  • 输入#1

    5 3
    2 2 2 2 2
    3 5 2 1 4
    1 3
    2 2
    4 5
    

    输出#1

    12
    16
    18
    
  • 输入#2

    3 3
    5 1 4
    5 1 4
    3 3
    2 2
    1 1
    

    输出#2

    17
    22
    11
    
首页