fork download
  1. /*Bismillahir Rahmanir Raheem*/
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define kuka ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);
  7. #define pb push_back
  8. #define sz(x) x.size()
  9. #define all(x) x.begin(), x.end()
  10. #define FOR(n) for(int i = 0; i < n; i++)
  11. #define ff(x, y) for( int y = 0; y < x; y++)
  12. #define fff(x, y) for( int y = x; y <= 0; y--)
  13. #define F first
  14. #define S second
  15. //#define int long long
  16.  
  17. typedef long long ll;
  18. typedef unsigned long long ull;
  19. typedef long double ld;
  20.  
  21. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  22.  
  23. const ll INF = LLONG_MAX;
  24. const int inf = INT_MAX;
  25. const int N = 1e5 + 5;
  26. const int MOD = 1e9 + 7;
  27.  
  28. int n, L;
  29. ld d[N], v[N];
  30. ld pref_t[N], pref_s[N];
  31.  
  32. ld get() {
  33. ld ans = 1e15;
  34.  
  35. for (int i = 1; i <= n; i++) {
  36. pref_t[i] = pref_t[i - 1] + ((ld)d[i] / (ld)v[i]);
  37. pref_s[i] = pref_s[i - 1] + d[i];
  38. }
  39.  
  40. for (int i = 1; i <= n; i++) {
  41. int l = i - 1, r = n + 1;
  42.  
  43. while (r - l > 1) {
  44. int mid = (l + r) / 2;
  45. if (pref_s[mid] - pref_s[l] < L) {
  46. l = mid;
  47. } else {
  48. r = mid;
  49. }
  50. }
  51.  
  52. ld sum = pref_t[i - 1] + pref_t[n] - pref_t[l];
  53. if (l < n) {
  54. ld last = L - (pref_s[l] - pref_s[i - 1]);
  55. if (l + 1 <= n) {
  56. sum += last / v[l + 1];
  57. }
  58. }
  59. ans = min(ans, sum);
  60. }
  61.  
  62. return ans;
  63. }
  64.  
  65. void oyan() {
  66. cin >> n >> L;
  67. for (int i = 1; i <= n; i++) {
  68. cin >> d[i];
  69. }
  70. for (int i = 1; i <= n; i++) {
  71. cin >> v[i];
  72. }
  73.  
  74. ld ans1 = get();
  75.  
  76. reverse(d + 1, d + n + 1);
  77. reverse(v + 1, v + n + 1);
  78.  
  79. ld ans2 = get();
  80.  
  81. cout << fixed << setprecision(9) << min(ans1, ans2) << "\n";
  82. }
  83.  
  84.  
  85. main(){
  86. kuka;
  87. //freopen("test.txt", "r", stdin);
  88. //freopen("distance.in", "r", stdin);
  89. //freopen("distance.out", "w", stdout);
  90. int oylan = 1;
  91. //cin>>oylan;
  92. while(oylan--){
  93. oyan();
  94. }
  95. }
  96. /*
  97. NOTES
  98. a/b module == (a*b^(module - 2)) % (module);
  99.  
  100. ll binpow(int n, int k) {
  101. if (k == 0) {
  102. return 1;
  103. }if (k % 2 == 0) {
  104. ll val = binpow(n, (k / 2));
  105. return val * val % MOD;
  106. }
  107. return (binpow(n, k - 1) * n) % MOD;
  108. }
  109. */
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1000000000000000.000000000