fork download
  1. /**
  2.  * Author: Praveen Ojha
  3.  * Created: 11 February 2019
  4.  * Time: 01:12:49
  5. **/
  6. #include <stdio.h>
  7. using namespace std;
  8. #define mod 1000000007
  9. #define PI 3.141592653589793238510
  10. #define all(x) (x).begin(),(x).end()
  11. #define rall(x) (x).rbegin(),(x).rend()
  12. #define __ ios_base::sync_with_stdio(false);cin.tie(NULL);
  13. typedef long long ll;
  14. typedef long double ld;
  15.  
  16. int main(){//__
  17. ll n,k;
  18. scanf("%lld %lld",&n,&k);
  19. ll a[n+1];
  20. a[0]=0;
  21. for(ll i=1;i<=n;i++){
  22. scanf("%lld",&a[i]);
  23. }
  24. ld maxi=0;
  25. for(ll i=2;i<=n;i++){
  26. a[i]+=a[i-1];
  27. }
  28. for(ll i=k;i<=n;i++){
  29. //cout<<"k:"<<i<<"\n";
  30. for(ll start=1;start+i-1<=n;start++){
  31.  
  32. ld sumi=a[start+i-1]-a[start-1];
  33. //cout<<"\n";
  34. sumi=(ld)sumi/(ld)i;
  35. if(sumi>maxi)
  36. maxi=sumi;
  37. }
  38. }
  39. printf("%.10Lf\n",maxi);
  40. return 0;
  41. }
Success #stdin #stdout 0s 15232KB
stdin
4 3
3 4 1 2
stdout
2.6666666667