Hi everyone, so I'm currently working on the Two-City Scheduling (LC # 1029) problem and I can't seem to wrap my head around the idea of the comparator. I looked up a couple of videos explaining how a comparator works, but still stuck. Mainly I'm confused as to how the values are sorted because for this problem we're given say,
costs = [[10,20],[30,200],[400,50],[30,20]] a 2-D array/vector and is sorted using ...
sort(costs.begin(), costs.end(), [](const vector<int>& a, const vector<int>& b)
{
return(a[0] - a[1]) < (b[0] - b[1]));
} ```
I guess what I'm mainly confused on or what I'm looking for an explanataion on is the return statement line and how those indicies are affliated with the original vector<vector<int>> costs and how they can be split up to vector a and vector b.
Any help would be greatly appreciated! Thanks! :)