4
1 10
1 20
1 8
2
I have submitted it using map and after storing iterating from end still getting tle … ?
An easy way to solve the problem is to store the first position of box(n/3), say var and see the shifts of this element. Only two cases are held. One case is if n divisible by 3 and var greater than new value inserted, we shift one behind. Its symmetric case is if n not divisible by 3 and var less than or equal to new value inserted, we shift one ahead.
Link to Solution : https://www.codechef.com/viewsolution/15162429
I trid it this like this but it gave TLE in my submission
Check my solution https://www.codechef.com/viewsolution/17097907
Help me to rectify my mistake
Alternate approach
There is a simpler solution. We use 2 multi-sets. One stores the top 1/3 elements, other stores the bottom 2/3 elements.
Here is a link to a well commented solution of this problem.
JAVA people, whoever is struggling to get rid of TLE for this problem, use BufferedWriter and BufferedReader that will reduce time a lot
The official editorial is not helpful!
Had much trouble in understanding!
Nice solution at : https://github.com/executable16/CodeChef/blob/master/RP.cpp
Mail me if any doubts : [email protected]