Advertisement
SalmaYasser

Two City Scheduling

Dec 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. static bool cmp (const vector <int> &v1 , const vector <int> &v2)
  2. {
  3. return (v1[0] - v1[1] < v2[0] - v2[1]);
  4. }
  5. int twoCitySchedCost(vector<vector<int>>& costs) {
  6.  
  7. int res = 0;
  8.  
  9. sort (costs.begin(), costs.end(), cmp);
  10.  
  11. for (int i = 0 ; i < costs.size()/2 ; i++ )
  12. {
  13. res += costs[i][0] + (costs[costs.size()/2 + i][1]);
  14. }
  15. return res;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement