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
|
||||||||||||||
2019-12-26 02:53:47
Nice problem. You can use a priority queue for getting the greatest and second greatest :) |
||||||||||||||
2019-12-07 08:09:27
nice one! |
||||||||||||||
2019-12-03 06:27:26
AC on first try |
||||||||||||||
2019-10-06 18:15:10
AC IN ONE GO. |
||||||||||||||
2019-08-20 11:33:42
AC in single go..!! A must practice problem for segment trees. |
||||||||||||||
2019-06-24 20:01:05
AC in one go >> awsm problem learnt segment tree |
||||||||||||||
2019-06-23 13:37:31
@ab_biswas09 even easiest of the easiest seg tree problems are not easy , are you red on codeforces |
||||||||||||||
2019-05-28 21:43:39
100th :) |
||||||||||||||
2019-05-01 11:35:10
AC in 1 go! segment tree <3 |
||||||||||||||
2019-03-03 05:49:07
AC IN ONE GO >> Cakewalk |