Sphere Online Judge

SPOJ Problem Set (classical)

1043. Can you answer these queries I

Problem code: GSS1

You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows:
Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i ≤ j ≤ y }.
Given M queries, your program must output the results of these queries.

Input

  • The first line of the input file contains the integer N.
  • In the second line, N numbers follow.
  • The third line contains the integer M.
  • M lines follow, where line i contains 2 numbers xi and yi.

Output

    Your program should output the results of the M queries, one query per line.

Example

Input:
3 
-1 2 3
1
1 2
Output:
2

Added by:Nguyen Dinh Tu
Date:2006-11-01
Time limit:1s-2s
Source limit:5000B
Languages:All except: CLOJ ERL F# JS PERL 6 TECS

hide comments
2010-07-25 13:11:38 naive_coder
plz tell why i m getting nzec..runtime...?
2010-06-27 15:17:22 Fidel Schaposnik
What is the bound on M? Is it always true that x_i < y_i? Is it possible to choose an empty interval (if all the numbers in the range [x_i, y_i] are negative)?

Last edit: 2010-08-13 19:58:25
2009-10-21 14:57:41 Slobodan
> Would a program be rejected if it executes in less than one second?
No, of course :) It just mean that *upper* time limits for the test cases are in range [1, 2] sec. Lower time limit for each test case is 0 seconds.

Last edit: 2009-10-21 14:57:57
2009-10-19 19:05:10 Seshadri R
What is the meaning of Time limit as 1s-2s? Would a program be rejected if it executes in less than one second?
SPOJ System © 2010 Sphere Research Labs. All Rights Reserved.