-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpeaks.cpp
More file actions
65 lines (50 loc) · 1.24 KB
/
peaks.cpp
File metadata and controls
65 lines (50 loc) · 1.24 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
// uncomment the two following lines if you want to read/write from files
// ifstream cin("input.txt");
// ofstream cout("output.txt");
int N, M;
cin >> N >> M;
vector<int> A(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
vector<int> B(M), C;
for (int i = 0; i < M; ++i){
cin >> B[i];
}
long long P = 0;
// INSERT YOUR CODE HERE
bool high;
int col = 0;
for (int i=0; i<N; i++) {
high = true;
if (i != 0) if (A[i] <= A[i-1]) {
high = false;
continue;
}
if (i != N-1) if (A[i] <= A[i+1]) {
high = false;
continue;
}
if (high) col ++;
}
for (int i=0; i<M; i++) {
high = true;
if (i != 0) if (B[i] <= B[i-1]) {
high = false;
continue;
}
if (i != M-1) if (B[i] <= B[i+1]) {
high = false;
continue;
}
if (high) P += col;
}
cout << P << endl;
return 0;
}