Codeforces Round #576 (Div. 2) A - City Day
Codeforces Round #576 (Div. 2)
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-rainyday 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 dis 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≤10^9), 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天的降雨量和一个x,一个y
问你 最早 的哪天降雨量满足前x天降雨量和后y天降雨量都大于这天的降雨量。
思路:直接从1到n每个点枚举前x个数和后y个数,直到找到符合条件的可行解,输出是最早的第几天。
有个坑点就是如果找前x个数或后y个数越界了,直接跳过,不影响可行解,只由降雨量不符合才影响可行解。
1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 #include<cstring>
5 #include<map>
6 #include<set>
7 #include<vector>
8 #include<algorithm>
9 #include<queue>
10 #include<unordered_map>
11 #include<list>
12 using namespace std;
13 #define ll long long
14 const int mod=1e9+7;
15 const int inf=1e9+7;
16
17 const int maxn=1e5+5;
18
19 int num[maxn];
20
21 int main()
22 {
23 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
24
25 int n,x,y;
26
27 while(cin>>n>>x>>y)
28 {
29 memset(num,0,sizeof(num));
30
31 for(int i=1;i<=n;i++)
32 cin>>num[i];
33
34 for(int i=1;i<=n;i++)//枚举1到n是否为可行解
35 {
36 int now=i;//当前i
37
38 int flag=0;
39 for(int j=now-1;j>=now-x&&j>=1;j--)//向前枚举x个,
40 {
41 if(num[j]<num[now])//不符合刷新flag
42 {
43 flag=1;
44 break;
45 }
46 }
47
48 if(flag==1)//已经不符合,不用再枚举后y个,直接退出
49 continue;
50
51 for(int j=now+1;j<=now+y&&j<=n;j++)//枚举后y个
52 {
53 if(num[j]<num[now])//不符合刷新flag
54 {
55 flag=1;
56 break;
57 }
58 }
59
60 if(flag==0)
61 {
62 cout<<now<<endl;//输出最优解
63 break;
64 }
65
66 }
67
68 }
69
70 return 0;
71 }