We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5b42185 commit 82074ecCopy full SHA for 82074ec
Two City Scheduling
@@ -0,0 +1,34 @@
1
+class Solution {
2
+public:
3
+ static bool comp(vector<int> a, vector<int> b)
4
+ {
5
+ return (abs(a[0]-a[1]) > abs(b[0]-b[1]));
6
+ }
7
+
8
+ int twoCitySchedCost(vector<vector<int>>& costs)
9
10
+ int ans = 0;
11
+ sort(costs.begin(), costs.end(), comp);
12
+ for(int i=0;i<costs.size();i++)
13
+ cout<<costs[i][0]<<" "<<costs[i][1]<<"\n";
14
+ int n=costs.size();
15
+ int a = n/2, b = n/2;
16
17
18
19
+ if(b==0 || (costs[i][0] <= costs[i][1] and a>0))
20
21
+ ans += costs[i][0];
22
+ a--;
23
24
+ else
25
26
+ ans += costs[i][1];
27
+ b--;
28
29
30
+ cout<<a<<" "<<b
31
+; return ans;
32
33
34
+};
0 commit comments