Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- //freopen("in.txt", "r", stdin);
- int n;
- scanf("%d", &n);
- int arr[n];
- for(int i=0; i<n; i++) scanf("%d", &arr[i]);
- int low = 0, high = n-1, best;
- while(low < high){
- int mid1 = low + (low+high)/3;
- int mid2 = high - (low+high)/3;
- if(arr[mid1] < arr[mid2]){
- high = mid2-1;
- best = mid1;
- }
- else {
- low = mid1+1;
- best = mid2;
- }
- }
- cout << best;
- }
Advertisement
Add Comment
Please, Sign In to add comment