#include<bits/stdc++.h>
using namespace std;
const int maxn=5e4+10;
int v[maxn];
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int h, w; cin >> h >> w;
for(int i=1;i<=w;i++) cin >> v[i];
int id=1, tam=1, resp=0, oq=-1;
while(id<=w){
resp+=tam;
if(oq==0){
if(v[id]>v[id+1]) tam++;
else{
tam=2;
oq=1;
}
}else if(oq==1){
if(v[id]<v[id+1]) tam++;
else{
tam=2;
oq=0;
}
}else{
tam++;
if(v[id]>v[id+1]) oq=0;
else oq=1;
}
id++;
}
cout << resp << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |