Problem:-
Armenia and Azerbaijan are in a state of war. Both these countries are separated by a long stretch of mountains of unequal heights. Each country sends its soldiers on the border and these soldiers will have to take position on one of the mountain i.e. 2 mountains will be occupied by two different armies. Uzairovic is a Russian who is acting as a double spy. He asks the Armenians to choose their mountain before the other army chooses theirs but he places two conditions:
1.Armenia will have to march forward and choose a mountain which is largest in height as compared to all the moutains which they have encountered up till now. But in this way, they can choose more than one mountain. So to avoid this, Uzairovic places another condition:
2.Armenia will have to choose the mountain which is the median of all the possible choices from condition 1.
The Armenians are very happy and thank Uzairovic for giving them the advantage of choosing the mountain first. But they don’t know that Uzairovic has planned to plant a bomb in the mountain which will be choosen by Armenia before they arrive there. Help Uzairovic succeed in his mission by giving him the position of the mountain which will decide the fate of the war.
Note: Armenia is to the right of mountains below. Positions start from 0, with the mountain closest to Azerbaijan positioned as 0.
Input:
The first line of input contains an integer n (1<n<1000) – the number of mountains separating the two countries. The next line contains the height of mountains a[ i ], starting from the mountain closest to Azerbaijan , where 1< a[ i ] < 1000.
Output:
Print an integer that refers to the position of the mountain that will be selected by Armenia. In case of more than one position as your answer, print the one which is closest to Azerbaijan.
code (c++):-
Code (c):-
- Very Cool numbers | Hacker earth solution
- Birthday party | Hacker earth solution
- Most frequent | hacker earth problem solution
- program to find symetric difference of two sets
- cost of balloons | Hacker earth problem solution
- Chacha o chacha | hacker earth problem solution
- jadu and dna | hacker earth solution
- Bricks game | hacker earth problem
- Anti-Palindrome strings | hacker earth solution
- connected components in the graph | hacker earth data structure
- odd one out || hacker earth problem solution
- Minimum addition | Hackerearth Practice problem
- The magical mountain | Hackerearth Practice problem
- The first overtake | Hackerearth Practice problem
Data structure:-
- Program to find cycle in the graph
- Implementation of singly link list
- Implementation of queue by using link list
- Algorithm of quick sort
- stack by using link list
- program to find preorder post order and inorder of the binary search tree
- Minimum weight of spanning tree
- Preorder, inorder and post order traversal of the tree
Key points:-
0 Comments