-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFEB-LTIME-HILLS-ver2.cpp
90 lines (75 loc) · 1.48 KB
/
FEB-LTIME-HILLS-ver2.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
Contest: FEB-LTIME
Host: CodeChef
Problem: HILLS
Current Submission Status : WA
*/
int checkPossibility(long int fromHill, long int toHill, long int u, long int d){
if(toHill == fromHill){
return 1;
}
else if (toHill > fromHill)
{
if(toHill - fromHill <= u){
return 1;
}
else
return 0; //cannot -- too high
}
else if (toHill < fromHill){
if(fromHill - toHill <= d){
return 1;
}
else{
return -1; //need parachute -- too low
}
}
}
#include <bits/stdc++.h>
#define MAX 110
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
//printf("test case:%d\n", t);
int n, count, a;
long int u,d;
long int h[MAX];
count=0;
cin>>n;
//cout<<n<<endl;//
cin>>u>>d;
//cout<<u<<" "<<d<<endl;//
for(int i=1; i<=n; i++){
cin>>h[i];
}
for(int i=2; i<=n; i++){
//cout<<"i="<<i<<endl;
//cin>>h[i];
if(i>1){
a=checkPossibility(h[i-1], h[i], u, d);
if(a==1){
//printf("Reached %d\n", i);
if(i==n){
//cout<<"n="<<n<<"i="<<i<<endl;//
printf("%d\n", i);
}
}
else if(a==-1){
//printf("Reached %d\n", i);
count++;
if(count==2){
printf("%d\n", i-1);
}
}
else if (a==0)
{
printf("%d\n", i-1);
break;
}
}
}
}
return 0;
}