Skip to content

Instantly share code, notes, and snippets.

@praneethreddymallupally
Created June 12, 2020 09:49
Show Gist options
  • Save praneethreddymallupally/daf7841857cc45429ca5b5425cd7fd71 to your computer and use it in GitHub Desktop.
Save praneethreddymallupally/daf7841857cc45429ca5b5425cd7fd71 to your computer and use it in GitHub Desktop.
Data Structures and Algorithms
class Solution {
static bool comparator(vector<int>& a,vector<int>& b)
{
return a[1]-a[0] > b[1]-b[0];
}
public:
int twoCitySchedCost(vector<vector<int>>& costs) {
int n = costs.size();
sort(costs.begin(),costs.end(),comparator);
int ans = 0;
for(int i=0;i<n;++i)
ans += i>=n/2?costs[i][1]:costs[i][0];
return ans;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment