add: 220702

This commit is contained in:
Eat-Swap 2022-07-03 00:27:12 +08:00
parent 2290ac579c
commit 6d6fe0fc25
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
2 changed files with 26 additions and 1 deletions

25
cpp/2207/220702.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <vector>
#include <algorithm>
/**
* 1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
* You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where:
* - horizontalCuts[i] is the distance from the top of the rectangular cake to the ith horizontal cut and similarly, and
* - verticalCuts[j] is the distance from the left of the rectangular cake to the jth vertical cut.
* Return the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays horizontalCuts and verticalCuts. Since the answer can be a large number, return this modulo 109 + 7.
*/
class Solution {
public:
static int maxArea(int h, int w, std::vector<int>& hc, std::vector<int>& vc) {
const int hcn = hc.size(), vcn = vc.size();
std::sort(hc.begin(), hc.end());
std::sort(vc.begin(), vc.end());
int hm = std::max(hc.front(), h - hc.back()), vm = std::max(vc.front(), w - vc.back());
for (int i = 1; i < hcn; ++i)
hm = std::max(hm, hc[i] - hc[i - 1]);
for (int i = 1; i < vcn; ++i)
vm = std::max(vm, vc[i] - vc[i - 1]);
return (static_cast<long long>(hm) * static_cast<long long>(vm)) % 1000000007;
}
};

View File

@ -3,4 +3,4 @@ PROJECT(2207)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2207 220702-CN.cpp)
ADD_EXECUTABLE(2207 220702.cpp)