A. City Day
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the n days of summer. On the i-th day, ai millimeters of rain will fall. All values ai are distinct.
The mayor knows that citizens will watch the weather x days before the celebration and y days after. Because of that, he says that a day d is not-so-rainy if ad is smaller than rain amounts at each of x days before day d and and each of y days after day d. In other words, ad<aj should hold for all d−x≤j<d and d<j≤d+y. Citizens only watch the weather during summer, so we only consider such j that 1≤j≤n.
Help mayor find the earliest not-so-rainy day of summer.
Input
The first line contains three integers n, x and y (1≤n≤100000, 0≤x,y≤7) — the number of days in summer, the number of days citizens watch the weather before the celebration and the number of days they do that after.
The second line contains n distinct integers a1, a2, …, an (1≤ai≤109), where ai denotes the rain amount on the i-th day.
Output
Print a single integer — the index of the earliest not-so-rainy day of summer. We can show that the answer always exists.
Examples
input
10 2 2
10 9 6 7 8 3 2 1 4 5
output
3
input
10 2 3
10 9 6 7 8 3 2 1 4 5
output
8
input
5 5 5
100000 10000 1000 100 10
output
5
Note
In the first example days 3 and 8 are not-so-rainy. The 3-rd day is earlier.
In the second example day 3 is not not-so-rainy, because 3+y=6 and a3>a6. Thus, day 8 is the answer. Note that 8+y=11, but we don’t consider day 11, because it is not summer.
**题意:**找出第一个前x个数和后y个数的每个数字比当前数小的下标
**思路:**暴力枚举,注意边界处理
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main() {
int n, x, y, a[100005] = {0};
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
int flag = 0, flag1 = 0;
for (int j = i - 1; j > i - x; j--) {
if (j <= 0) break; // j<=0时已经超过边界,直接结束当前枚举
if (a[j] < a[i]) flag = 1;
}
for (int j = i + 1; j <= i + y; j++) {
if (j > n) break; // j>n时已经超过边界,直接结束当前枚举
if (a[j] < a[i]) flag1 = 1;
}
if (flag == 0 && flag1 == 0) {
printf("%d\n", i);
break;
}
}
return 0;
}