这题不就是要求一个区间使得 i<j 且a[i]<a[j] 然后求所有满足条件的区间的长度的最大值吗?觉得这个思路没有问题,但是码不能过。那么这个思路哪里错了呢?求大佬举出反例。
代码如下
#include <bits/stdc++.h>
using namespace std;
int n;
int h=1, t=1;
int a[100001];
int ans;
int main() {
scanf("%d", &n);
for (int i=1; i<=n; i++) {
scanf("%d", &a[i]);
}
while (t <= n) {
while ( (a[t+1]>a[t]) && (t<n) ) {
t = t + 1;
}
ans = max(ans, t-h+1);
t = t + 1;
h = t;
}
if (ans == 1) ans = 0;
printf("%d", ans);
return 0;
}