2 ^ 33 is around 10^9 . so while loop in my code will run 33 time in worst case ( means if largest element in an array is 10^9 ,2 will divide it 33 times to become 1 ) so sorting will also perform atmost 33 times only.
read my code in above reply while going through these lines.
you can find many resources easily to learn to analyse time complexity of an algorithm, just google it .
@will_of_ken
You need to sort the array after every operation…
Use priority queue… it automatically sorts array after each operation…
suppose you have
16 2 2 1 1 as array…
then you will remove 16 then 8 then 4 and then 2… but your code removes 16 ,2 , 2 ,1 ,… etc.
Yours is O(T*n*30*log(n)) = O(5.10 * 10^8)
My first approach was O(T*n*30*log(n*30))= O(6.6* 10^8)
Mine is TLE
my second approach was with same time complexity as yours which passes in 0.42 secs
Too strict time limit… I hate author for keeping it that strict and that too in a short contest…
i already have a backup plan of O(T nlog(n) ) as after every iteration of while loop i will get two sorted arrays ( first segment of all starting elements which isn’t contributed to A and other which contributed) and it takes only linear time to merge two sorted arrays.
Hopefully time limit is not strict … I love the author for not keeping it strict that too in a short contest
@shivamchef
Authors solution is O(T*n*30*log(n)) (takes 0.45 secs link)
Its strict according to intended solution…
I hate author for keeping it that strict and that too in a short contest… XD
I modified it a bit i.e. instead of breaking loop when A>=Z if i break when A+X>B+Y
I am getting WA.could you please check it ,why is it happening?
here is link:CodeChef: Practical coding for everyone
1
1 2 4 10 9 83
1
Refer this test case…
here lldA>lldB but still you need one contribution to beat… ( to avoid a situation where both achieves the score together and opponent wins as per que)