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
hide comments
mayank goyal:
20130619 12:43:54
Can anyone look at my code plz..I am getting TLE.Link to my code is https://ideone.com/aas60x 

mayank goyal:
20130619 12:21:35
getting TLE using segment trees in java 

Swarnaprakash:
20130313 18:24:58
Sabarinath (npsabari@) and Nikola Jovanovic (randomusername@)


RandomUsername:
20130228 11:47:45
@npsabari's comment is true. I had the same problem with N>10^5. Just make the array size 2*10^5 and it will work. Last edit: 20130228 11:48:30 

Tushar Makkar (Retired):
20130118 14:15:29
Last edit: 20130806 12:19:17 

Janani:
20121230 18:39:38
Should this be done using segment tree? 

npsabari:
20121212 19:44:58
Careful.. number of integers in the array is > 10^5.. 

Haidar Abboud:
20120723 18:00:16
piece of cake 

sandeep pandey:
20120424 02:04:56
Nice One..:) 
Added by:  Swarnaprakash 
Date:  20090110 
Time limit:  0.357s0.857s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO NODEJS PERL6 VB.NET 
Resource:  Kurukshetra 09 OPC 