A. City Day

传送门

A. City Day

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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.

题意:输入n天数,前a天,后b天,求存在最早一天的降雨量均小于前a天,后b天,输出该天数。

思路:只需要找出某个区间中的最小数即可,对数组进行遍历即可。

代码

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int a[100000];
int main()
{
	int n, x, y, i, j, flag = 0;
	scanf("%d %d %d", &n, &x, &y);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (i = 0; i < n; i++)
	{
		flag = 0;
		for (j = i - x; j <= i + y; j++)
		{
			if (j < 0 || j >= n)
			{
				continue;
			}
			if (a[i] > a[j])
			{
				flag= 1;
			}
		}
		if (flag == 0)
		{
			printf("%d\n", i + 1);
			break;
		}
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稚皓君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值