GSS2 - Can you answer these queries II

Being a completist and a simplist, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse to write two program of same kind at all. So he always failes in contests.

When having a contest, Yang Zhe looks at the score of every problems first. For the problems of the same score, Yang Zhe will do only one of them. If he's lucky enough, he can get all the scores wanted.

Amber is going to hold a contest in SPOJ. She has made a list of N candidate problems, which fit Yang Zhe very well. So Yang Zhe can solve any problem he want. Amber lined up the problems, began to select. She will select a subsequence of the list as the final problems. Being A girl of great compassion, she'd like to select such a subsequence (can be empty) that Yang Zhe will get the maximal score over all the possible subsequences.

Amber found the subsequence easily after a few minutes. To make things harder, Amber decided that, Yang Zhe can take this contest only if Yang Zhe can answer her Q questions. The question is: if the final problems are limited to be a subsequence of list[X..Y] (1 <= X <= Y <= N), what's the maximal possible score Yang Zhe can get?

As we know, Yang Zhe is a bit idiot (so why did he solve the problem with a negative score?), he got Wrong Answer again... Tell him the correct answer!


  • Line 1: integer N (1 <= N <= 100000);
  • Line 2: N integers denoting the score of each problem, each of them is a integer in range [-100000, 100000];
  • Line 3: integer Q (1 <= Q <= 100000);
  • Line 3+i (1 <= i <= Q): two integers X and Y denoting the ith question.


  • Line i: a single integer, the answer to the ith question.


4 -2 -2 3 -1 -4 2 2 -6
1 2
1 5
4 9


Warning: large input/output data,be careful with certain languages

hide comments
sahil1422: 2019-12-11 10:31:22

So dreadful explanation. Admins, please look into the question.

Last edit: 2019-12-11 10:31:51
gmon20: 2019-08-27 19:38:20

Last edit: 2019-08-27 19:41:42
sharkert1k28: 2019-08-04 07:50:06

it's ez problem !

lightninguz: 2019-07-13 18:23:18

f**k...reading comprehension+data structure problem...u can see a lot of problems with horrible explanation like this in China...

george_123: 2019-07-12 08:36:59

hard to understand the problem

danos: 2019-07-03 08:32:57

Horrible explanation

intruder_p: 2019-06-22 16:45:46

My solution is failing again and again. Can anyone please provide some good sample test case?

sudhanshu6324: 2019-02-28 20:47:28

first convince urself about ouput for the following input
1 2 -1 3 2 -1 2 -1
1 8
2 8


Last edit: 2019-02-28 20:48:04
sudhanshu6324: 2019-02-28 20:21:38

Horrible explanation

cegprakash: 2019-01-06 00:41:15

4 1 2 4
1 4
Is the answer 7 or 11?

Added by:Fudan University Problem Setters
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO
Resource:Description, standard program and test data by Yang Zhe