Number of days in Luogu P1567 and Luogu p1567
Background
Statistical days
Description
In the hot summer, KC is very uncomfortable. He would rather endure the cold Arctic than the summer in Xiamen. Recently, he began to study weather changes. He hopes to use the research results to predict the future weather.
He collected the highest temperature data for N (1 <= N <= 10 ^ 7) consecutive days.
Now he wants to know the maximum number of consecutive days that the maximum temperature has been rising.
Input/Output Format
Input Format:
* Row 1: an integer N. 1 <= N <= 10 ^ 7
* Row 2: an integer separated by N spaces, indicating the maximum temperature for N consecutive days. 0 <= maximum temperature <= 10 ^ 9.
Output Format:
* Row 1: an integer that indicates the maximum number of consecutive days that the maximum temperature has been rising.
Input and Output sample input sample #1: Copy
101 2 3 2 4 5 6 8 5 9
Output example #1: Copy
5
Description
Time limit 1 s memory limit 128 MB
Xjb simulation ..
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAXN=1e7+10;inline int read(){ char c=getchar();int flag=1,x=0; while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();} while(c>='0'&&c<='9')x=x*10+c-48,c=getchar();return x*flag;}int n;int a[MAXN];int main(){ n=read(); for(int i=1;i<=n;i++)a[i]=read();a[0]=0x7ffff; int now=0,mx=0; for(int i=1;i<=n;i++) { if(a[i]>=a[i-1])now++,mx=max(now+1,mx); else now=0; } printf("%d",mx); return 0;}