Language: C++

#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<double> p(N);

    rep(i, N) cin >> p[i];
    double sum = 0;
    int index = 0;
    rep(i, K) sum += p[i];
    repd(i, K, N) {
        double res = sum - p[i - K] + p[i]; 
        if (sum < res) {
            index = i - K + 1;
            sum = res;
        }
    }

    ll l = 1, res = 0;
    repd(i, index, index + K) {
        l = lcm(l, p[i]);
    }

    repd(i, index, index + K) {
        ll s = ((p[i] + 1) * p[i]) / 2.0;
        // cout << s << " " << (l / p[i]) << endl;
        res += s * (l / p[i]);
    }

    double ans = (double)res / l;
    printf("%.10lf\n", ans);
    return 0;
}

Compiler output:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:58,
                 from a.cc:1:
/usr/include/c++/14/numeric: In instantiation of 'constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn) [with _Mn = long long int; _Nn = double; common_type_t<_Mn, _Nn> = double]':
a.cc:41:16:   required from here
   41 |         l = lcm(l, p[i]);
      |             ~~~^~~~~~~~~
/usr/include/c++/14/numeric:190:43: error: static assertion failed: std::lcm arguments must be integers
  190 |       static_assert(is_integral_v<_Mn> && is_integral_v<_Nn>,
      |                                           ^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/numeric:190:43: note: 'std::is_integral_v<double>' evaluates to false
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/type_traits: In instantiation of 'struct std::make_unsigned<double>':
/usr/include/c++/14/type_traits:2076:11:   required by substitution of 'template<class _Tp> using std::make_unsigned_t = typename std::make_unsigned::type [with _Tp = double]'
 2076 |     using make_unsigned_t = typename make_unsigned<_Tp>::type;
      |           ^~~~~~~~~~~~~~~
/usr/include/c++/14/numeric:199:34:   required from 'constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn) [with _Mn = long long int; _Nn = double; common_type_t<_Mn, _Nn> = double]'
  199 |       _Ct __r = __m2 / __detail::__gcd<make_unsigned_t<_Ct>>(__m2, __n2);
      |                        ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:41:16:   required from here
   41 |         l = lcm(l, p[i]);
      |             ~~~^~~~~~~~~
/usr/include/c++/14/type_traits:1929:13: error: invalid use of incomplete type 'class std::__make_unsigned_selector<double, false, false>'
 1929 |     { using type = typename __make_unsigned_selector<_Tp>::__type; };
      |             ^~~~
/usr/include/c++/14/type_traits:1837:11: note: declaration of 'class std::__make_unsigned_selector<double, false, false>'
 1837 |     class __make_unsigned_selector;
      |           ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/numeric: In instantiation of 'constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn) [with _Mn = long long int; _Nn = double; common_type_t<_Mn, _Nn> = double]':
a.cc:41:16:   required from here
   41 |         l = lcm(l, p[i]);
      |             ~~~^~~~~~~~~
/usr/include/c++/14/numeric:205:48: error: argument 1 in call to function '__builtin_mul_overflow' does not have integral type
  205 |       bool __overflow = __builtin_mul_overflow(__r, __n2, &__r);
      |                                                ^~~