static Double M(Double[] prices, Integer[] volumes, Integer capacity) {

        Double[] sol, mySol;
        Double myFinalSol;

        sol = new Double[prices.length];
        mySol = new Double[prices.length];

        if (capacity == 0) {
            return 0.0;
        }

        for (int i = 0; i < prices.length; ++i) {
            if (capacity >= volumes[i]) {
                sol[i] = M(prices, volumes, capacity - volumes[i]);
            } else {
                sol[i] = 0.0;
            }
        }

        Double a;
        Double b;

        for (int i = 0; i < prices.length; ++i) {
            if (capacity >= volumes[i]) {
                mySol[i] = sol[i] + prices[i];
            } else {
                mySol[i] = 0.0;
            }
        }

        myFinalSol = mySol[0];
        for (int i = 1; i < prices.length; ++i) {
            if (mySol[i] > myFinalSol) {
                myFinalSol = mySol[i];
            }
        }
        return myFinalSol;
    }