class Solution {
public:
int minimumCost(int m, int n, vector<int>& horizontalCut, vector<int>& verticalCut) {
int x=1,y=1;//x代表纵向看蛋糕的数量 y代表横向看蛋糕的数量
int res=0;
sort(horizontalCut.begin(),horizontalCut.end());
sort(verticalCut.begin(),verticalCut.end());
while(horizontalCut.size()>0 && verticalCut.size()>0){
if(verticalCut.back()>=horizontalCut.back()){
res+=y*verticalCut.back();
verticalCut.pop_back();
x++;
}
else{
res+=x*horizontalCut.back();
horizontalCut.pop_back();
y++;
}
}
while(verticalCut.size()>0){
res+=y*verticalCut.back();
verticalCut.pop_back();
x++;
}
while(horizontalCut.size()>0){
res+=x*horizontalCut.back();
horizontalCut.pop_back();
y++;
}
return res;
}
};
思维题 先把单刀开销最大的切了