Submit | All submissions | Best solutions | Back to list |
KGSS - Maximum Sum |
This will be indicated in the input by a 'U' followed by space and then two integers i and x.
U i x, 1 ≤ i ≤ N, and x, 0 ≤ x ≤ 10^8.
This operation sets the value of A[i] to x.
Query:This will be indicated in the input by a 'Q' followed by a single space and then two integers i and j.
Q x y, 1 ≤ x < y ≤ N.
You must find i and j such that x ≤ i, j ≤ y and i != j, such that the sum A[i]+A[j] is maximized. Print the sum A[i]+A[j].
Input
The first line of input consists of an integer N representing the length of the sequence. Next line consists of N space separated integers A[i]. Next line contains an integer Q, Q ≤ 10^5, representing the number of operations. Next Q lines contain the operations.
Output
Output the maximum sum mentioned above, in a separate line, for each Query.
Example
Input: 5 1 2 3 4 5 6 Q 2 4 Q 2 5 U 1 6 Q 1 5 U 1 7 Q 1 5 Output: 7 9 11 12
Added by: | Swarnaprakash |
Date: | 2009-01-10 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | Kurukshetra 09 OPC |
hide comments
|
||||||||||||||
2018-02-02 20:45:41
My 50th !!! AC in ONE GO !!! |
||||||||||||||
2018-01-01 22:55:23
There can be 2 approaches here: 1> Use a structure array for the max and second max 2> A modification of the Range Maximum Query. After getting AC on 1st one, go for the second one. :) |
||||||||||||||
2017-12-20 00:36:46
Please do take sufficienty large array for the tree. Costed me four SIGSEGV errors. |
||||||||||||||
2017-12-17 18:54:04
AC in one go..Simple Segment tree with a slight variation of range min |
||||||||||||||
2017-12-15 16:30:41
Simple segment tree implementation!! |
||||||||||||||
2017-11-11 08:53:54
Nice Question...AC in one GO:) |
||||||||||||||
2017-10-30 06:40:43
Input limit 10^8 , but for integer data type verdict is runtime error ??? What's amaging!!!!! |
||||||||||||||
2017-10-29 06:29:18
AC IN ONE GO!!! Was an easy one, added experience with segment tree though |
||||||||||||||
2017-09-14 11:52:22
AC in ONE GO..!!! Nice implementation category question |
||||||||||||||
2017-09-12 13:28:16 VENUKANT SAHU
AC in one go :) |