题解链接:http://www.cygmasot.com/index.php/2015/09/23/codeforces_580/
题意:the length of the maximum non-decreasing subsegment
直接搞,水题
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
using namespace std;
template <class T>
inline bool rd(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
template <class T>
inline void pt(T x) {
if (x <0) {
putchar('-');
x = -x;
}
if (x>9) pt(x / 10);
putchar(x % 10 + '0');
}
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1e9;
const int N = 1e5+10;
int n;
int a[N];
int main() {
rd(n);
for (int i = 1; i <= n; i++)rd(a[i]);
int ans = 1;
for (int i = 2, pre = 1; i <= n; i++) {
if (a[i] >= a[i - 1]) {
pre++;
}
else pre = 1;
ans = max(ans, pre);
}pt(ans);
return 0;
}
题意:有一个双关键字的数组,共n个元素。常数d
选任意个使得选出的元素中 第一关键字(最大的-最小的)<d
并且使得第二关键字和最大。
问:最大的和是多少。
思路:
先排个序,然后two pointers搞搞,枚举左端点,右端点是单调的。
#inclu