Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MAXN = 100005;
- int speed[MAXN], dist[MAXN];
- int main()
- {
- // freopen("input.txt", "r", stdin);
- ios_base::sync_with_stdio(0);
- int n,k;
- cin>>n>>k;
- for (int i = 0; i < n; ++i)
- {
- cin>>speed[i]>>dist[i];
- }
- long double lo = 0.0, hi = k;
- for (int i = 0; i < 200; ++i)
- {
- long double m1 = lo+((hi-lo)/3.0);
- long double m2 = hi-((hi-lo)/3.0);
- long double min1 = 1e20, max1 = -1e20, min2 = 1e20, max2 = -1e20;
- for (int i = 0; i < n; ++i)
- {
- long double val = (speed[i]*m1) + dist[i];
- min1 = min(min1, val);
- max1 = max(max1, val);
- val = (speed[i]*m2) + dist[i];
- min2 = min(min2, val);
- max2 = max(max2, val);
- }
- max1-=min1;
- max2-=min2;
- if(max1 < max2)
- hi = m2;
- else
- lo = m1;
- }
- long double min1 = 1e20, max1 = -1e20;
- for (int i = 0; i < n; ++i)
- {
- long double val = (speed[i]*lo) + dist[i];
- min1 = min(min1, val);
- max1 = max(max1, val);
- }
- double ans = max1-min1;
- cout.precision(6);
- cout<<fixed<<ans<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement