-
Notifications
You must be signed in to change notification settings - Fork 0
/
laser.cpp
36 lines (35 loc) · 938 Bytes
/
laser.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
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, u;
cin >> n >> u;
ll E[n];
for (int i=0; i<n; i++) {
cin >> E[i];
}
ll i=0, j = 1;
long double eff = 0, eps = 1e-9;
while (i < n) {
while (j<n and E[j]-E[i]<u) {
j++;
}
if (j==n) j--;
if (j-i+1 >= 3) {
// cout << i << " " << j << " " << E[j]-E[i];
if (E[j]-E[i] <= u) {
long double tmp = 1.0f * (E[j]-E[i+1]) / (E[j]-E[i]);
if (eps + eff < tmp ) eff = tmp;
}
if (E[j-1]-E[i] <= u and (j-i)>=3) {
long double tmp = 1.0f * (E[j-1]-E[i+1]) / (E[j-1]-E[i]);
if (eps + eff < tmp ) eff = tmp;
}
// cout << " " << eff << "\n";
}
i++;
}
if (eff == 0.0f) eff = -1.0;
printf("%.12Lf\n", eff);
return 0;
}