Monday, March 26, 2018

DCP-420: Minimum Cost Devskill Problem Solution

https://devskill.com/CodingProblems/ViewProblem/420

#include<bits/stdc++.h>

// Nayeem Mollick Joy , Applied Physics & Electronic Engineering , University of Rajshahi.

using namespace std;

int main()

{
    vector<int>joy;
    int t,n,i,count;
    cin>>t;
    while(t--)
    {
        cin>>i;
        while(i--)
        {
            cin>>n;
            joy.push_back(n);
        }
        count=0;
        sort(joy.begin(),joy.end());
        int mn=joy[0];
        vector<int>::iterator iter=joy.begin();
        for(iter;iter!=joy.end();iter++)
        {
            count=count+((*iter)-mn);
        }
        cout<<count<<endl;
        joy.clear();
    }
    return 0;
}

No comments:

Post a Comment