lower_bound and upper_bound от HackerRank задача
Здравейте,
задачата е за работа с lower_bound and upper_bound; Направих няколко оптимизации на решението, но все още дава на няколко теста "Terminated due to timeout". Някакви идеи?
(оптимизации: максималния елемент го намирам още на вход; После проверка, ако числото е > от максималния, директно принтя изход )
Условието е :
You are given integers in the sorted order. Then you are given queries. In each query you will be given an integer and you have to tell whether that integer is present in the array, if so you have to tell at which index it is present and if it is not present you have to tell the index at which the smallest integer that is just greater than the given number is present.
The first line of the input contains the number of integers . The next line contains integers in sorted order. The next line contains , the number of queries. Then lines follow each containing a single integer .
If the same number is present multiple times, you have to print the first index at which it occurs.
Ето кода: