Sunday, July 20, 2014

TopCoder High School SRM 43 Level one - 250 pt - Transform Array solution

TopCoder High School SRM 43 Level one - 250 pt - Transform Array statement: http://community.topcoder.com/stat?c=problem_statement&pm=6692&rd=10792

TopCoder High School SRM 43 Level one - 250 pt - Transform Array editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm43

TopCoder High School SRM 43 Level one - 250 pt - Transform Array solution: 


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class TransformArray {
    public: int doTransform(vector <int> a) {
        int cnt=0;
        sort(a.begin(), a.end());
        for(int i=1; i<a.size(); i++) cnt+=a[i-1], a[i]-=a[i-1], a[i-1]=0;
        return cnt;
    }
};

No comments:

Post a Comment