Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
Vasya adores sport programming. He can't write programs but he loves to watch the contests 'ss ss. Vasya even has a favorite Coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participant and track the progress of his coolness. for each contest where this coder participant, he wrote out a single non-negative number-the number of points his favorite
Coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously ).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder
Earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns Strictly less points
That he earned on each past contest. a coder's first contest isn't considered amazing. now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. but the list of earned points turned out
Long and Vasya can't code... that's why he asks you want to help him.
Input
The first line contains the single integerN(1 digit ≤ DigitNLimit ≤00001000)
-The number of contests where the coder participant.
The next line containsNSpace-separated non-negative integer numbers-they are the points which the coder has earned. The points are given
In the chronological order. All points do not exceed 10000.
Output
Print the single number-the number of amazing performances the coder has had during his whole history of participating in the contests.
Sample test (s) Input
5100 50 200 150 200
Output
2
Input
104664 6496 5814 7010 5762 5736 6944 4850 3698 7242
Output
4
Note
In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances Number 2, 4, 9 and 10 are amazing.
Solution: This is to determine whether the next number is outside the previous maximum and minimum values. When two variables are input, the maximum and minimum values are recorded and the values outside the specified range can be found.
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int main(){int i,n;int max,min;int sum;int a[1001];max=1;min=10000;sum=0;scanf("%d",&n);scanf("%d",&a[0]);max=a[0];min=a[0];for(i=1;i<n;i++){scanf("%d",&a[i]);if(a[i]>max){max=a[i];sum++;}if(a[i]<min){min=a[i];sum++;}}printf("%d\n",sum); return 0;}