题目描述
blablabla
暴力枚举即可。
PS:题意并不是严格上升,不降即可。 2 3 3 3 10 应该输出7
Code:
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n;
int a[N];
int main() {
while (cin >> n) {
for (int i = 1; i <= n; i ++) cin >> a[i];
int res = 0;
for (int i = 2; i <= n; i ++) {
int t = a[i - 1], p = i;//用p来记录下 下下标,如果出现了变化,则说明出现了非递减连续子序列,更新答案即可。
while (a[i] >= a[i - 1]) i ++;
if (p != i) {
res = max(res, a[i - 1] - t);
i --;
}
}
cout << res << endl;
}
return 0;
}
感谢!我以为题目是说严格上升的,一直找不出哪里出错
感谢支持~ 加油