矩形蛋糕的高度爲 h 且寬度爲 w,給你兩個整數數組 horizontalCuts 和 verticalCuts,其中 horizontalCuts[i] 是從矩形蛋糕頂部到第 i 個水平切口的距離,類似地, verticalCuts[j] 是從矩形蛋糕的左側到第 j 個豎直切口的距離。
請你按數組 horizontalCuts 和 verticalCuts 中提供的水平和豎直位置切割後,請你找出 面積最大 的那份蛋糕,並返回其 面積 。由於答案可能是一個很大的數字,因此需要將結果對 10^9 + 7 取餘後返回。
示例 1:
輸入:h = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3]
輸出:4
解釋:上圖所示的矩陣蛋糕中,紅色線表示水平和豎直方向上的切口。切割蛋糕後,綠色的那份蛋糕面積最大。
示例 2:
輸入:h = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1]
輸出:6
解釋:上圖所示的矩陣蛋糕中,紅色線表示水平和豎直方向上的切口。切割蛋糕後,綠色和黃色的兩份蛋糕面積最大。
示例 3:
輸入:h = 5, w = 4, horizontalCuts = [3], verticalCuts = [3]
輸出:9
提示:
2 <= h, w <= 10^9
1 <= horizontalCuts.length < min(h, 10^5)
1 <= verticalCuts.length < min(w, 10^5)
1 <= horizontalCuts[i] < h
1 <= verticalCuts[i] < w
題目數據保證 horizontalCuts 中的所有元素各不相同
題目數據保證 verticalCuts 中的所有元素各不相同
class Solution {
public:
int f(int len, vector<int>&v)
{
sort(v.begin(),v.end());
int ans=max(v[0],len-v[v.size()-1]);
for(int i=1;i<v.size();i++)ans=max(ans,v[i]-v[i-1]);
return ans;
}
int maxArea(int h, int w, vector<int>& horizontalCuts, vector<int>& verticalCuts) {
long long a=f(h,horizontalCuts),b=f(w,verticalCuts);
return a*b%1000000007;
}
};