Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define int long long
- using namespace std;
- signed main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n, u;
- cin >> n >> u;
- vector<int> q(n);
- for(int i = 0; i < n; i++){
- cin >> q[i];
- }
- int ans = -1;
- int a, b, c;
- for(int i = 0; i < n - 2; i++){
- int l = i + 2;
- int r = n;
- while(l + 1 < r){
- int mid = (l + r) / 2;
- if(q[mid] - q[i] <= u){
- l = mid;
- }
- else{
- r = mid;
- }
- }
- if(q[l] - q[i] > u) continue;
- if(ans == -1 || (c - a) * (q[l] - q[i]) < (q[l] - q[i + 1]) * (c - b))
- {
- c = q[l];
- b = q[i];
- a = q[i + 1];
- ans = 0;
- }
- }
- if(ans == -1){
- cout << ans << endl;
- }
- else{
- double x1 = 1.0;
- cout << fixed << setprecision(20) << (c - a) * x1 / (c - b);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement