Educational Round 93, Codeforces

 In Bad Triangle we have given sorted integers in ascending order & we have to return three indices such that its impossible to form triangle with that. If its possible to form then return -1.


We all know property of triangle :

a + b > c
a + c > b
c + b > a

 

So  basically we have to return indices by which we cannot form a triangle. Since the array element is sorted in ascending order we can simply check for 0, 1, n-1 elements. If its impossible to form with these three value it will be impossible for the rest.


Solution

 

In Substring Removal Game Alex & Bob are given string. They have to maximize number of 1's they take out from the string. Also the 1's must be in continuous manner. Alex moves 1st & then Bob & so on. We have to find score of Alex.

 

So its obvious that for winning both will try to remove as much 1 as possible. Since Alex moves 1st hence he take highest number of 1 present in continuous manner, then 2nd highest will be taken by bob, 3rd highest by alex & so on. 


Approach : Maintain count of continuous 1, sort them in descending order & finally alternately pick the count & calculate the sum.

 

Solution

No comments:

If you have any doubt or suggestion let me know in comment section.

Powered by Blogger.