-
Notifications
You must be signed in to change notification settings - Fork 1
/
Day64.cpp
48 lines (32 loc) · 1.01 KB
/
Day64.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
int minimumCostOfBreaking(vector<int> vec1, vector<int> vec2, int m, int n){
int vertical = 1;
int horizental = 1;
sort(vec1.begin() , vec1.end() , greater<int>());
sort(vec2.begin() , vec2.end() , greater<int>());
int i=0;
int j=0;
int cost = 0;
while(i < m-1 && j < n-1 ){
if(vec2[j] >= vec1[i] ){
cost += vec2[j] * horizental;
vertical++;
j++;
}
else{
cost += vec1[i] * vertical;
horizental++;
i++;
}
}
while(i < m-1){
cost += vec1[i] * vertical;
horizental++;
i++;
}
while(j < n-1){
cost += vec2[j] * horizental;
vertical++;
j++;
}
return cost;
}