#include <iostream>
#include <vector>
// Function to find the pivot element
int findPivot(std::vector<int>& arr, int n) {
int left = 0, right = n - 1;
while (left < right) {
int mid = left + (right - left) / 2;
if (arr[mid] > arr[left]) {
left=mid;
} else {
right=mid-1;
}
}
return left;
}
int main() {
std::vector<int> arr = {5, 8, 5, 2, 0};
int n = arr.size();
int pivotIndex = findPivot(arr, n);
if (pivotIndex != n) {
std::cout << "Index: " << pivotIndex << ", Value: " << arr[pivotIndex] << std::endl;
} else {
std::cout << "No pivot found" << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKLy8gRnVuY3Rpb24gdG8gZmluZCB0aGUgcGl2b3QgZWxlbWVudAppbnQgZmluZFBpdm90KHN0ZDo6dmVjdG9yPGludD4mIGFyciwgaW50IG4pIHsKICAgIGludCBsZWZ0ID0gMCwgcmlnaHQgPSBuIC0gMTsKICAgIHdoaWxlIChsZWZ0IDwgcmlnaHQpIHsKICAgICAgICBpbnQgbWlkID0gbGVmdCArIChyaWdodCAtIGxlZnQpIC8gMjsKICAgICAgICBpZiAoYXJyW21pZF0gPiBhcnJbbGVmdF0pIHsKICAgICAgICAgICAgbGVmdD1taWQ7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmlnaHQ9bWlkLTE7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGxlZnQ7Cn0KCmludCBtYWluKCkgewogICAgc3RkOjp2ZWN0b3I8aW50PiBhcnIgPSB7NSwgOCwgNSwgMiwgMH07CiAgICBpbnQgbiA9IGFyci5zaXplKCk7CiAgICBpbnQgcGl2b3RJbmRleCA9IGZpbmRQaXZvdChhcnIsIG4pOwogICAgaWYgKHBpdm90SW5kZXggIT0gbikgewogICAgICAgIHN0ZDo6Y291dCA8PCAiSW5kZXg6ICIgPDwgcGl2b3RJbmRleCA8PCAiLCBWYWx1ZTogIiA8PCBhcnJbcGl2b3RJbmRleF0gPDwgc3RkOjplbmRsOwogICAgfSBlbHNlIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIk5vIHBpdm90IGZvdW5kIiA8PCBzdGQ6OmVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==