-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path17.cpp
More file actions
41 lines (41 loc) · 760 Bytes
/
Copy path17.cpp
File metadata and controls
41 lines (41 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//Find the minimum element in a rotated and sorted array.
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl "\n"
#define mod 1000000007
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
void inputarr(int arr[], int n) {
REP(i, 0, n) {
cin >> arr[i];
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int arr[n];
inputarr(arr, n);
int l = 0, h = n - 1, m = 0;
while (l <= h) {
m = (l + h) / 2;
if (arr[m] < arr[m - 1])
break;
else if (arr[m] < arr[h]) {
h = m - 1;
} else {
l = m + 1;
}
}
if (l == 0 && h == 0)
cout << arr[0];
else
cout << arr[m];
}