fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lli long long int
  4. #define mp(a,b) make_pair(a,b)
  5. #define pb(a) push_back(a)
  6. #define fr(i,n) for(i=0;i<n;i++)
  7. #define F first
  8. #define S second
  9. #define fast std::ios_base::sync_with_stdio(false)
  10. #define mod 1000000007
  11. #define pi 3.14159265
  12. int main() {
  13. fast;
  14. lli n,k;
  15. cin>>n>>k;
  16. lli a[n],i;
  17. fr(i,n)
  18. {
  19. cin>>a[i];
  20. }
  21. double b[n],sum=0,ans=0;
  22. fr(i,n)
  23. {
  24. b[i]=(float)(a[i]+1)/2;
  25. }
  26. fr(i,k)
  27. {
  28. sum+=b[i];
  29. }
  30. ans=sum;
  31. for(i=k;i<n;i++)
  32. {
  33. sum-=b[i-k];
  34. sum+=b[i];
  35. ans=max(ans,sum);
  36. }
  37. cout<<fixed<<setprecision(8)<<ans;
  38.  
  39. return 0;
  40. }
Runtime error #stdin #stdout 0s 4556KB
stdin
Standard input is empty
stdout
Standard output is empty