From 807dc8da342a81af155e03238fc58dcc9874ad8e Mon Sep 17 00:00:00 2001 From: Eatswap Date: Sat, 29 Oct 2022 18:07:14 +0800 Subject: [PATCH] add: 221029 --- cpp/2210/221029.cpp | 32 ++++++++++++++++++++++++++++++++ cpp/2210/CMakeLists.txt | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 cpp/2210/221029.cpp diff --git a/cpp/2210/221029.cpp b/cpp/2210/221029.cpp new file mode 100644 index 0000000..32d1bdf --- /dev/null +++ b/cpp/2210/221029.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +/** + * 2136. Earliest Possible Day of Full Bloom + * + * You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each: + * plantTime[i] is the number of full days it takes you to plant the ith seed. Every day, you can work on planting exactly one seed. You do not have to work on planting the same seed on consecutive days, but the planting of a seed is not complete until you have worked plantTime[i] days on planting it in total. + * - growTime[i] is the number of full days it takes the ith seed to grow after being completely planted. After the last day of its growth, the flower blooms and stays bloomed forever. + * - From the beginning of day 0, you can plant the seeds in any order. + * Return the earliest possible day where all seeds are blooming. + */ + +class Solution { +public: + static int earliestFullBloom(const std::vector& plantTime, const std::vector& growTime) { + std::multiset, std::greater<>> s; + for (int i = 0; i < plantTime.size(); ++i) + s.insert({growTime[i], plantTime[i]}); + int ans = 0, cur = 0; + for (const auto& [gt, pt] : s) + ans = std::max(ans, gt + (cur += pt)); + return ans; + } +}; + +int main() { + Solution::earliestFullBloom({1,2,3,2},{2,1,2,1}); + return 0; +} diff --git a/cpp/2210/CMakeLists.txt b/cpp/2210/CMakeLists.txt index e7d9982..5dc51c2 100644 --- a/cpp/2210/CMakeLists.txt +++ b/cpp/2210/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2210) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2210 221028.cpp) +ADD_EXECUTABLE(2210 221029.cpp)