-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjd1.cpp
42 lines (38 loc) · 770 Bytes
/
jd1.cpp
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
42
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool Split(const vector<int>& arr, int beg, int end, int groups)
{
if (groups <= 1) return true;
for (int i = 1; i <= end - beg + 1 - (groups); ++i)
{
if (*std::max_element(arr.begin()+beg, arr.begin()+beg + i)
> *std::min_element(arr.begin()+beg + i, arr.begin()+end))
{
continue;
}
else
{
return Split(arr, beg+i, end, groups-1);
}
}
return false;
}
int main()
{
int N;
cin >> N;
vector<int> heights;
for (int i = 0, tmp; i != N; ++i)
{
cin >> tmp;
heights.push_back(tmp);
}
// io done
int groups = 2;
while (Split(heights, 0, heights.size(), groups))
groups++;
cout << groups - 1;
return 0;
}