PEWDSVTS - Editorial (Unofficial)

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 .

1 Like

Could you please help me finding my bug in this problem? :sob:
https://www.codechef.com/viewsolution/24074877

@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.

YOUR CODE EDITED
see this edit in your soln.
It TLE because of not using priority queue…
SAMPLE AC CODE using pq

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 :frowning_face:
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 :frowning_face: and that too in a short contest…

2 Likes

@l_returns
Thanks a lot… :heart_eyes:
I understand… :blush:

1 Like

You’re welcome :smiley:

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 :slight_smile: that too in a short contest

1 Like

@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 :frowning_face: and that too in a short contest… XD

1 Like

@l_returns
I submitted my O(T * n * log(n) ) and it is taking 0.78 secs link. can u tell the reason? ( Actually i am newbie at Div 1).

1 Like

@shivamchef
actually its O(T*n*log(n) + T*(z-b)/y ) == O(1.051 *10^10)
Now it seems like there were weak test cases also :frowning_face:
Anyways here are your AC optimized solutions…
CodeChef: Practical coding for everyone (0.12 secs with fast i/o)
CodeChef: Practical coding for everyone (0.34 without fast i/o)

1 Like

ok! just icremented value of A using formula and got link (0.34 secs).
Thnkx :slight_smile:

2 Likes

lol we are working parallel. XD!!

1 Like

XD… Btw I am sorry I posted your solution link on official editorial page…

Thanks a lot.
I was doing the same mistake.

2 Likes

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)

1 Like

Thanks.
I didn’t thought of that.

1 Like

Thanks for tutorial :slight_smile:

1 Like

Can anyone help me in debugging CodeChef: Practical coding for everyone ?
I am getting TLE.

Can you help me in getting cross this TLE CodeChef: Practical coding for everyone ?