-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathsir.cpp
46 lines (42 loc) · 1011 Bytes
/
sir.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# include <fstream>
# include <algorithm>
# include <deque>
# define NR 100005
using namespace std;
ifstream f("sir.in");
ofstream g("sir.out");
deque <int> m, M;
int n,X,Y,Z,l,sol,L,ci,i;
int a[NR];
void adauga (int i)
{
while (m.size() && a[m.back()] > a[i])
m.pop_back();
m.push_back(i);
while (M.size() && a[M.back()] < a[i])
M.pop_back();
M.push_back(i);
}
int main ()
{
f>>n>>X>>Y>>Z;
ci=1;
for (i=1; i<=n; ++i) {
f>>a[i]; adauga (i);
if (i>=X) {
while ((ci+Y<=i || a[M.front()]-a[m.front()]>Z) && ci+X<=i+1) {
if (m.front()==ci) m.pop_front();
if (M.front()==ci) M.pop_front();
++ci;
}
if (ci+X<=i+1 && a[M.front()]-a[m.front()]<=Z) {
l=i-ci+1;
if (l>L) sol=ci, L=l;
else if (l==L) sol=ci;
}
}
}
if (sol==0) g<<"-1\n";
else g<<L<<" "<<sol<<" "<<sol+L-1<<"\n";
return 0;
}