codeforces 1199A(Codeforces Round #576 (Div. 2))

传送门:https://codeforces.com/contest/1199/problem/A
Codeforces Round #576 (Div. 2)
A
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 ? days of summer. On the ?-th day, ?? millimeters of rain will fall. All values ?? are distinct.

The mayor knows that citizens will watch the weather ? days before the celebration and ? days after. Because of that, he says that a day ? is not-so-rainy if ?? is smaller than rain amounts at each of ? days before day ? and and each of ? days after day ?. In other words, ??<?? should hold for all ?−?≤?<? and ?<?≤?+?. Citizens only watch the weather during summer, so we only consider such ? that 1≤?≤?.

Help mayor find the earliest not-so-rainy day of summer.

Input
The first line contains three integers ?, ? and ? (1≤?≤100000, 0≤?,?≤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 ? distinct integers ?1, ?2, …, ?? (1≤??≤109), where ?? denotes the rain amount on the ?-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
inputCopy
10 2 2
10 9 6 7 8 3 2 1 4 5
outputCopy
3
inputCopy
10 2 3
10 9 6 7 8 3 2 1 4 5
outputCopy
8
inputCopy
5 5 5
100000 10000 1000 100 10
outputCopy
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+?=6 and ?3>?6. Thus, day 8 is the answer. Note that 8+?=11, but we don't consider day 11, because it is not summer.


题意:找出j日,要求j日前x天比他大,后y天比他大。

#include<iostream>
#include<cstdio>
using namespace std;
const int maxn =1e6+5;
int n,x,y;
int arr[maxn];
int main(){
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<=n;i++)
        scanf("%d",&arr[i]);
    int ans=0;
    for(int i=1;i<=n;i++){
        bool fla=true;
        for(int j=i-1;j>0&&i-j<=x;j--){//前头指针遍历
            if(arr[j]<arr[i]){
                fla=false;
                break;
            }
        }
        for(int j=i+1;j<=n&&j-i<=y;j++){//后头指针遍历
            if(arr[j]<arr[i]){
                fla=false;
                break;
            }
        }
        if(fla){
            ans=i;
            break;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值