1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <cstdio>
#include <cstdint>
#include <vector>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iostream>
#include <cstring>
#include <iomanip>

using namespace std;

int n, t;

const int ZERO_CORRECT_INDEX = 50007;

const int VEC_SIZE = 2*ZERO_CORRECT_INDEX+50;

vector<long double>* sureUpToNow;
vector<long double>* working;
vector<long double> inputData;

vector<long double>* createVector()
{
    vector<long double>* result = new vector<long double>(VEC_SIZE);
    for(int i =0;i<result->size();++i)
    {
        (*result)[i] = 0.0L;
    }

    (*result)[ZERO_CORRECT_INDEX] = 1.0L;

    return result;
}

void init()
{
    scanf("%d %d", &n, &t);

    for(int i = 0; i < n; ++i)
    {
        long double a;
        scanf("%Lf",&a);
        inputData.push_back(a);
    }
    sort(inputData.rbegin(), inputData.rend());

    sureUpToNow = createVector();
    working = createVector();
    (*sureUpToNow)[ZERO_CORRECT_INDEX] = 1.0L;
}

long double resultIfAddNewNumber(int currentIndex)
{
    long double currentOdd = inputData[currentIndex];
    long double currentNegativeOdd = 1.0L - currentOdd;

    //zero working set
    for(int i = 0; i<=currentIndex+3;++i)
    {
        (*working)[ZERO_CORRECT_INDEX-i] = 0;
        (*working)[ZERO_CORRECT_INDEX+i] = 0;
    }


    int maxNumbersCorrectOrWrongAfter = currentIndex + 1;
    

    for(int i = ZERO_CORRECT_INDEX - maxNumbersCorrectOrWrongAfter; i<= ZERO_CORRECT_INDEX + maxNumbersCorrectOrWrongAfter; ++i)
    {
        (*working)[i]
            = (*sureUpToNow)[i-1] * currentOdd 
            + (*sureUpToNow)[i+1] * currentNegativeOdd;
    }

    //for(int i = ZERO_CORRECT_INDEX - maxNumbersCorrectOrWrongAfter; i<= ZERO_CORRECT_INDEX + maxNumbersCorrectOrWrongAfter; ++i)
    //{
    //    printf("%Lf ", (*working)[i]);
    //}
    //cout<<endl;

    vector<long double> oddsToSum; 
    for(int i = t; i<=currentIndex+1; ++i)
    {
        oddsToSum.push_back((*working)[ZERO_CORRECT_INDEX + i]);
    }
    sort(oddsToSum.begin(), oddsToSum.end());
    
    long double theSum = accumulate(oddsToSum.begin(), oddsToSum.end(), 0.0L);
    return theSum;

}


int main ()
{
    init();

    long double bestProbability = (t==0)?1.0L:0.0L;
    for (int i =0;i<inputData.size();++i)
    {

        long double potentialResult = resultIfAddNewNumber(i);
        //printf("Pot result: %.19Lf\n", potentialResult);

        swap(working, sureUpToNow);
        bestProbability = max(potentialResult, bestProbability);
    }


    printf("%.18Lf\n", bestProbability);
}