-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnimodalArray.cpp
More file actions
45 lines (44 loc) · 979 Bytes
/
UnimodalArray.cpp
File metadata and controls
45 lines (44 loc) · 979 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
42
43
44
45
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n; cin >> n;
vector<int> a(n+1);
for(int i = 1; i <= n; i++)
cin >> a[i];
int ok = false;
for(int i = 1; i <= n; i++)
{
for(int j = i; j <= n; j++)
{
//[1..i..j..n]
int fm = 1;
for(int k = i; k+1 <= j; k++)
if(a[k] != a[k+1])
fm = 0;
int fl = 1;
for(int k = 1; k+1 <= i; k++)
if(a[k+1] <= a[k])
fl = 0;
int fr = 1;
for(int k = j; k+1 <= n; k++)
if(a[k+1] >= a[k])
fr = 0;
if(fm && fl && fr)
{
ok = true;
break;
}
if(ok)
break;
}
if(ok)
break;
}
if(ok)
cout << "YES\n";
else
cout << "NO\n";
return 0;
}