#include <bits/stdc++.h>
#include <fstream>
using namespace std;
long long x;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
cin >> x; long long tym1 = x; long long tym2 = x;
int wynik1 = 0; int wynik2 = 0;
vector <int> v;
for(int i = 0; i < n-1;i++)
{
cin >> x;
v.push_back(x);
if(i%2==0)
{
if(x<=tym1)
{
wynik1 += 1;
//cout << "wynik1 : "<<i<<"\t";
tym1 = 10000000;
continue;
}
}
else{
if(x >= tym1)
{
wynik1 += 1;
//cout << "wynik1 : "<<i<<"\t";
tym1 = -10000000;
continue;
}
}
tym1 = x;
}
for(int i = 0; i < n-1; i++)
{
x = v.at(i);
if(i%2==0)
{
if(x>=tym2)
{
wynik2 += 1;
//cout << "wynik2 : "<<i<<"\n";
tym2 = -10000000;
continue;
}
}
else{
if(x <= tym2)
{
wynik2 += 1;
//cout << "wynik2 : "<<i<<"\n";
tym2 = 10000000;
continue;
}
}
tym2 = x;
}
//cout << wynik1 << " "<<wynik2 <<"\n";
cout << min(wynik1,wynik2);
return 0;
}
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 66 67 68 69 | #include <bits/stdc++.h> #include <fstream> using namespace std; long long x; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; cin >> x; long long tym1 = x; long long tym2 = x; int wynik1 = 0; int wynik2 = 0; vector <int> v; for(int i = 0; i < n-1;i++) { cin >> x; v.push_back(x); if(i%2==0) { if(x<=tym1) { wynik1 += 1; //cout << "wynik1 : "<<i<<"\t"; tym1 = 10000000; continue; } } else{ if(x >= tym1) { wynik1 += 1; //cout << "wynik1 : "<<i<<"\t"; tym1 = -10000000; continue; } } tym1 = x; } for(int i = 0; i < n-1; i++) { x = v.at(i); if(i%2==0) { if(x>=tym2) { wynik2 += 1; //cout << "wynik2 : "<<i<<"\n"; tym2 = -10000000; continue; } } else{ if(x <= tym2) { wynik2 += 1; //cout << "wynik2 : "<<i<<"\n"; tym2 = 10000000; continue; } } tym2 = x; } //cout << wynik1 << " "<<wynik2 <<"\n"; cout << min(wynik1,wynik2); return 0; } |
English