Hatena::Grouptopcoder

TopCoderの問題を解く

解いた問題の一覧表

2009-05-05

Pricing

| 07:49

問題文

652.34->985.81 / 1000

最大利益を求める問題。全てのケースを試せばよい。

class Pricing {
public:
    int maxSales(vector <int> price) {
        int maxSales = 0;
        int size = price.size();
        sort(price.begin(), price.end());
        for (int i = 0; i < size; i++) {
            for (int j = i; j < size; j++) {
                for (int k = j; k < size; k++) {
                    for (int l = k; l < size; l++) {
                        int sales = 0;
                        for (int m = 0; m < size; m++) {
                            if (price[m] >= price[l]) {
                                sales += price[l];
                            } else if (price[m] >= price[k]) {
                                sales += price[k];
                            } else if (price[m] >= price[j]) {
                                sales += price[j];
                            } else if (price[m] >= price[i]) {
                                sales += price[i];
                            }
                        }
                        maxSales = max(maxSales, sales);
                    }
                }
            }
        }
        return maxSales;
    }
};

EthanaelEthanael2011/07/22 23:14Ppl like you get all the brains. I just get to say thanks for he asewnr.

nwuzwsnwuzws2011/07/23 17:24hyvJcw <a href="http://snkjtvdtsudq.com/">snkjtvdtsudq</a>

tumzkdcbtumzkdcb2011/07/23 22:087LifN6 , [url=http://qcpqtmgyqoyx.com/]qcpqtmgyqoyx[/url], [link=http://aubgoopyvcjc.com/]aubgoopyvcjc[/link], http://wsyiiftrtiox.com/

jijaysgrhiqjijaysgrhiq2011/07/25 21:508QsglD <a href="http://gpbtdukulkdq.com/">gpbtdukulkdq</a>