diff --git a/2201/220120.cpp b/2201/220120.cpp new file mode 100644 index 0000000..ee67269 --- /dev/null +++ b/2201/220120.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +class Solution { +public: + static int minEatingSpeed(const std::vector& piles, int h) { + int L = 1, R = 0x7FFFFFFE; + // range: [L, R) + while (R - L > 1) { + int M = (L - 1 + R) >> 1, cnt = 0; + // test M + for (const int& i : piles) + cnt += (i / M) + ((i % M) ? 1 : 0); + *(cnt <= h ? &R : &L) = M + 1; + } + return L; + } +}; + +int main() { + // {34392671,891616382,813261297}, 712127987 + std::cout << Solution::minEatingSpeed({30,11,23,4,20}, 6); + return 0; +} diff --git a/2201/CMakeLists.txt b/2201/CMakeLists.txt index b0343b4..4d79054 100644 --- a/2201/CMakeLists.txt +++ b/2201/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2201) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2201 220119.cpp) \ No newline at end of file +ADD_EXECUTABLE(2201 220120.cpp) \ No newline at end of file