Sunday, June 29, 2014

TopCoder High School SRM 26 Level one - 250 pt - Third Buy Discount solution

TopCoder High School SRM 26 Level one - 250 pt - Third Buy Discount statement: http://community.topcoder.com/stat?c=problem_statement&pm=6745&rd=10650

TopCoder High School SRM 26 Level one - 250 pt - Third Buy Discount editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm26

TopCoder High School SRM 26 Level one - 250 pt - Third Buy Discount solution:

#include <iostream>
#include <vector>
#include <algorithm>

class ThirdBuyDiscount {
    public: double minCost(std::vector <int> p, int d) {
        int i=0;
        double cnt=.0;
        std::sort(p.begin(), p.end());
        while(i<p.size()-p.size()/3) cnt+=p[i], i++;
        while(i<p.size()) cnt+=(double)p[i]*(100-d)/100, i++;
        return cnt;
    }
};

No comments:

Post a Comment