From 6d6fe0fc25b2db37451dcc159defe3e948afd93e Mon Sep 17 00:00:00 2001 From: Eat-Swap Date: Sun, 3 Jul 2022 00:27:12 +0800 Subject: [PATCH] add: 220702 --- cpp/2207/220702.cpp | 25 +++++++++++++++++++++++++ cpp/2207/CMakeLists.txt | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 cpp/2207/220702.cpp diff --git a/cpp/2207/220702.cpp b/cpp/2207/220702.cpp new file mode 100644 index 0000000..43eb638 --- /dev/null +++ b/cpp/2207/220702.cpp @@ -0,0 +1,25 @@ +#include +#include + +/** + * 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& hc, std::vector& 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(hm) * static_cast(vm)) % 1000000007; + } +}; diff --git a/cpp/2207/CMakeLists.txt b/cpp/2207/CMakeLists.txt index 6b6a64c..3f2fa33 100644 --- a/cpp/2207/CMakeLists.txt +++ b/cpp/2207/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2207) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2207 220702-CN.cpp) +ADD_EXECUTABLE(2207 220702.cpp)